将 RSA 签名附加到文本文件

发布于 2024-11-14 22:53:50 字数 423 浏览 9 评论 0原文

我有一个文本文件,我必须使用 RSA 私钥对其进行签名,然后附加此签名并对这个“文本文件+签名”进行 AES 加密。

出于演示原因,我正在测试这样的加密文件。

我正在用 C 编写一个简单的程序来执行以下操作: 首先对文本文件进行 RSA 签名(1024 位)。 然后将签名附加到文本文件中 然后对文件进行 AES 加密。

然后执行AES解密 然后从文件中删除 128 字节签名。 然后对原始文本文件和解密后的文本文件进行RSA验证。

这是我的问题:

将二进制签名附加到文本文件是个好主意吗? 如果不是,一般的做法是什么?

我尝试了一个简单的程序来执行上述操作,但在 AES 解密中我总是收到一两个垃圾字符,因此 RSA 验证失败。

请建议。 对此类文件进行 AES 解密,然后删除 128 字节(1024 位模数)签名。

I have a text file that I have to sign with RSA private key and then append this signature and do an AES encryption over this "text file+signature".

For demonstration reasons I am testing such an encrypted file.

I am writing a simple program in C to do the following:
First do an RSA sign(1024 bit) on a text file.
Then append the signature to the text file
Then do an AES encryption over the file.

Then perform the AES decryption
Then remove the 128 byte signature from the file.
Then do an RSA verification of the original text file and the text file after decryption.

Here are my questions:

Is it a good idea to append a binary signature to a text file?
If no what is the general way this is done?

I tried a simple program to do the above but I always get one or two junk characters on AES decryption and therefore RSA verification fails.

Do please suggest.
an AES decrypt of such a file and then remove the 128 byte(1024 bit modulus) signature.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

走野 2024-11-21 22:53:50

隐私增强邮件不久前引入了在文本文件中嵌入加密信息的临时标准:基本上,二进制信息以 base-64 进行编码,并与标题行一起附加到文本文件中,以标识所添加内容的“剪切”点。

这是通常的示例(该块将添加到现有文本文件的末尾)


-----BEGIN PRIVACY-ENHANCED MESSAGE-----
Proc-Type: 4,ENCRYPTED
Content-Domain: RFC822
DEK-Info: DES-CBC,F8143EDE5960C597
Originator-ID-Symmetric: [email protected],,
Recipient-ID-Symmetric: [email protected],ptf-kmc,3
Key-Info: DES-ECB,RSA-MD2,9FD3AAD2F2691B9A,
          B70665BB9BF7CBCDA60195DB94F727D3
Recipient-ID-Symmetric: [email protected],ptf-kmc,4
Key-Info: DES-ECB,RSA-MD2,161A3F75DC82EF26,
         E2EF532C65CBCFF79F83A2658132DB47

LLrHB0eJzyhP+/fSStdW8okeEnv47jxe7SJ/iN72ohNcUk2jHEUSoH1nvNSIWL9M
8tEjmF/zxB+bATMtPjCUWbz8Lr9wloXIkjHUlBLpvXR0UrUzYbkNpk0agV2IzUpk
J6UiRRGcDSvzrsoK+oNvqu6z7Xs5Xfz5rDqUcMlK1Z6720dcBWGGsDLpTpSCnpot
dXd/H5LMDWnonNvPCwQUHt==
-----END PRIVACY-ENHANCED MESSAGE-----

The ad-hoc standard for embedding crypto information in text files was introduced by Privacy Enhanced Mail some time ago: Basically the binary information is encoded in base-64 and appended to the text file along with a header line to identify the "snip" point for the added content.

Here is a sample of what it typically looks like (this chunk would be added to the end of the existing text file)


-----BEGIN PRIVACY-ENHANCED MESSAGE-----
Proc-Type: 4,ENCRYPTED
Content-Domain: RFC822
DEK-Info: DES-CBC,F8143EDE5960C597
Originator-ID-Symmetric: [email protected],,
Recipient-ID-Symmetric: [email protected],ptf-kmc,3
Key-Info: DES-ECB,RSA-MD2,9FD3AAD2F2691B9A,
          B70665BB9BF7CBCDA60195DB94F727D3
Recipient-ID-Symmetric: [email protected],ptf-kmc,4
Key-Info: DES-ECB,RSA-MD2,161A3F75DC82EF26,
         E2EF532C65CBCFF79F83A2658132DB47

LLrHB0eJzyhP+/fSStdW8okeEnv47jxe7SJ/iN72ohNcUk2jHEUSoH1nvNSIWL9M
8tEjmF/zxB+bATMtPjCUWbz8Lr9wloXIkjHUlBLpvXR0UrUzYbkNpk0agV2IzUpk
J6UiRRGcDSvzrsoK+oNvqu6z7Xs5Xfz5rDqUcMlK1Z6720dcBWGGsDLpTpSCnpot
dXd/H5LMDWnonNvPCwQUHt==
-----END PRIVACY-ENHANCED MESSAGE-----
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文