Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I encrypt a string in vb.net using RijndaelManaged, and using PKCS5 padding?

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?

like image 375
digiguru Avatar asked Feb 27 '23 01:02

digiguru


1 Answers

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.

like image 119
President James K. Polk Avatar answered May 10 '23 09:05

President James K. Polk