Hello ASPeeps,
I'm new at .net programming and i have learnt a lot from aspsnippets.com and this forum.
However i have an issue when trying the Encrypt-and-Decrypt-QueryString-Parameter-Values-in-ASPNet-using-C-and-VBNet
The encryption works without any issues however when i want to decrypt i get the following exception. System.NullReferenceException: Object reference not set to an instance of an object.
Private Function Decrypt(cipherText As String) As String
Dim EncryptionKey As String = "MYOWNENCRYPTKEY"
'the line below triggers the error
cipherText = cipherText.Replace(" ", "+")
Dim cipherBytes As Byte() = Convert.FromBase64String(cipherText)
Using encryptor As Aes = Aes.Create()
Dim pdb As New Rfc2898DeriveBytes(EncryptionKey, New Byte() {&H49, &H76, &H61, &H6E, &H20, &H4D, _
&H65, &H64, &H76, &H65, &H64, &H65, _
&H76})
encryptor.Key = pdb.GetBytes(32)
encryptor.IV = pdb.GetBytes(16)
Using ms As New MemoryStream()
Using cs As New CryptoStream(ms, encryptor.CreateDecryptor(), CryptoStreamMode.Write)
cs.Write(cipherBytes, 0, cipherBytes.Length)
cs.Close()
End Using
cipherText = Encoding.Unicode.GetString(ms.ToArray())
End Using
End Using
Return cipherText
End Function
Please anyone have any idea why it isnt working. My Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.17929
I thank you in advance