-
Feb 11th, 2019, 09:39 AM
#1
Thread Starter
Lively Member
AES 256 encryption error
I have googled quite a bit and I still cannot figure out what I am doing wrong. I am trying to encrypt a password using the RijndaelManaged class?
I have so far:
function Encrypt(strValue as string) as string
dim IV as Byte() = New Byte(){}
dim SharedKey as Byte() = New Byte(){}
dim aes as New RijndaelManaged
aes.Padding = PaddingMode.PKCS7
aes.KeySize = 256
aes.Mode = CipherMode.CBC
Dim msEncrypt as New MemoryStream()
'I key the SharedKey and the IV as a hexadecimal string
SharedKey = System.Text.Encoding.ASCII.GetBytes("a long 64 character string")
IV = System.Text.Encoding.ASCII.GetBytes("a long 32 character string")
Dim csEncrypt As New CryptoStream(msEncrypt, aes.CreateEncryptor(SharedKey, IV), CryptoStreamMode.Write)
'Convert string value to byte array
Dim toEncrypt As Byte() = Encoding.GetEncoding(1252).GetBytes(strValue)
toEncrypt = Encoding.Convert(Encoding.GetEncoding(1252), Encoding.UTF8, toEncrypt)
'Perform encryption
csEncrypt.Write(toEncrypt, 0, toEncrypt.Length)
csEncrypt.FlushFinalBlock()
'Return Base64 string
Return Convert.ToBase64String(msEncrypt.ToArray())
end function
but I get this error:
Specified initialization vector (IV) does not match the block size for this algorithm.
please help!
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|