I've been working on devising out a VB.Net equivalent of the following PL-SQL code which encrypts user password :
The above code encrypts the word "kiran" to 411736CFE319B335114510FB196DCD0E
What I've been trying to do is this:
The above code does solid encryption but not the one desired. One obstacle is that in the PL-SQL code, PKCS5 padding is done. Whereas in my case, its PKCS7, as PKCS5 is not natively supported in VB 2005, framework 2.0. Can neone suggest what is to be done to get the desired result ?
VB.NET:
key VARCHAR(16) := 'A1B2C3D4E5F6G7H8';
encryption_mode NUMBER := DBMS_CRYPTO.ENCRYPT_AES128 + DBMS_CRYPTO.CHAIN_CBC + DBMS_CRYPTO.PAD_PKCS5;
RETURN DBMS_CRYPTO.ENCRYPT(UTL_I18N.STRING_TO_RAW (data, 'AL32UTF8'), encryption_mode, UTL_I18N.STRING_TO_RAW(key, 'AL32UTF8') );
The above code encrypts the word "kiran" to 411736CFE319B335114510FB196DCD0E
What I've been trying to do is this:
VB.NET:
Dim strText As String
strText = "kiran"
Try
Dim InputByteArray() As Byte = System.Text.Encoding.UTF8.GetBytes(strText)
Dim des As SymmetricAlgorithm = New RijndaelManaged
des.Key = System.Text.Encoding.UTF8.GetBytes("A1B2C3D4E5F6G7H8")
des.Padding = PaddingMode.PKCS7
des.Mode = CipherMode.CBC
Dim ms As New MemoryStream
Dim cs As New CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write)
cs.Write(InputByteArray, 0, InputByteArray.Length)
cs.FlushFinalBlock()
MsgBox("Encrypted string:" & Convert.ToBase64String(ms.ToArray()))
Catch ex As Exception
MsgBox(ex.Message)
End Try
The above code does solid encryption but not the one desired. One obstacle is that in the PL-SQL code, PKCS5 padding is done. Whereas in my case, its PKCS7, as PKCS5 is not natively supported in VB 2005, framework 2.0. Can neone suggest what is to be done to get the desired result ?