如何使用 RijndaelManaged 和 PKCS5 填充加密 vb.net 中的字符串?
我使用以下代码来初始化加密...
Dim symmetricKey As New System.Security.Cryptography.RijndaelManaged()
With symmetricKey
.Key = Encoding.ASCII.GetBytes(Key)
.IV = Encoding.ASCII.GetBytes(IV)
.Mode = CipherMode.CBC
.BlockSize = 128
.KeySize = 128
.Padding = PaddingMode.PKCS7
End With
要求是使用PKCS5。 vb.net 中的填充模式仅包括
- ANSIX923
- ISO10126
- 无
- PKCS7
- 零
所以我认为没有 PKCS5 的方法。有什么办法可以添加吗,还是需要自己写一个加密方法?如果是这样-我该怎么写?是否有可靠的 DLL 支持它?
I use the following code to initialize encryption...
Dim symmetricKey As New System.Security.Cryptography.RijndaelManaged()
With symmetricKey
.Key = Encoding.ASCII.GetBytes(Key)
.IV = Encoding.ASCII.GetBytes(IV)
.Mode = CipherMode.CBC
.BlockSize = 128
.KeySize = 128
.Padding = PaddingMode.PKCS7
End With
The requirement is to use PKCS5. Padding modes in vb.net only include
- ANSIX923
- ISO10126
- None
- PKCS7
- Zeros
So I don't think there is a method for PKCS5. Is there any way to add it, or do I need to write an encryption method myself? If so - how do I write that? Is there a reliable DLL that will support it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
PKCS7 填充和 PKCS5 填充是相同的。在这种情况下,它们是同义词。
编辑:
PKCS#7 填充在 PKCS#7 规范 部分中进行了描述10.3. PKCS#5 填充在 PKCS#5 规范 第 6.1.1 节中进行了描述步骤 4. 通过检查您可以看到,填充算法是相同的。
PKCS7 padding and PKCS5 padding are the same thing. In this context they are synonyms.
EDIT:
The PKCS#7 padding is described in the PKCS#7 spec in section 10.3. PKCS#5 padding is described in the PKCS#5 spec in section 6.1.1 step 4. As you can see by examination, the padding algorithms are identical.
我猜你需要其他人来读取你的加密数据,然后只理解这种填充。
您可能知道,PKCS5 的解释如下:
好吧,您已经有了信息 - 将字符串编码为 byte[],对其进行扩展,使其与 16 个字节对齐,然后根据配方填充其余部分。然后,使用 Padding.None 进行加密。
估计应该不会这么麻烦吧。无论如何,没有字符串加密,所以既然你将这些东西编码为 byte[] ,...
注意:代码不在我的脑海中,它根本无法运行...
I guess that you need someone else to read your encrypted data, and then only understand that kind of padding.
As you probably know, PKCS5 is explained as:
Well, you have your info - encode the string to byte[], extend it so it is aligned to 16 bytes, and fill the rest according to the recipe. Then, encrypt with Padding.None.
Guess it shouldn't be so troublesome. Anyway, there is no string encryption, so since you encode the stuff to byte[] anyway, ...
NOTE: code is out of my head, it's not runable at all...