Hi
I am attempting to use the Rijndael algorithm for encrypting and decrypting sql server username and password. I have been successful in the generation of the key and the IV, and in the encryption and decryption of the data. My problem arises when I attempt to store the key and IV in an external location.
Both the key and the IV are bytes(), I have a simple method that can convert the byte() into a string:
I also have a function that converts the string data into a byte():
When I attempt to user the IV in the decoding method I get the following error:
My encryption is:
My decryption is:
Appreciate any suggestions.
Mike55
I am attempting to use the Rijndael algorithm for encrypting and decrypting sql server username and password. I have been successful in the generation of the key and the IV, and in the encryption and decryption of the data. My problem arises when I attempt to store the key and IV in an external location.
Both the key and the IV are bytes(), I have a simple method that can convert the byte() into a string:
Visual Basic:
private function convertToString( byVal data as byte()) as string
dim enc as System.text.asciiencoding = new system.text.asciiencoding
converttostring = enc.getstring(data)
return converttostring
end function
I also have a function that converts the string data into a byte():
Visual Basic:
private function convertToByte(byVal data as string) as byte()
return (new unicodeencoding).getbytes(<<String data>>)
end function
When I attempt to user the IV in the decoding method I get the following error:
System.security.cryptography.cryptographicexception: Specified initialization vertoc (IV) does not match the block size for this algorith.
My encryption is:
Visual Basic:
dim fStream as filestream = file.open(filename, filemode.openorcreate)
dim rijndaelalg as rijndael = rijndael.create
dim cStream as new cryptostream)fstream, rijndaelalg.createEncryptor(key, IV), CryptoStreamMode.Write)
Dim sWriter as new streamwriter(cstream)
swriter.writeline(plaintext)
My decryption is:
Visual Basic:
dim fstream as filestream = file.open(filename, filemode.openorcreate)
dim rijndaelalg as rijndael = rijndael.create
dim cstream as new cryptostream(fstream, rijndaelalg.createdecryptor(convertToByte(key), convertToByte(IV)), CryptoStreammode.read)
dim sreader as new streamreader(cstream)
dim val as string = sreader.readline
Appreciate any suggestions.
Mike55
Last edited by a moderator: