S
Simon Whale
Hi All,
i am using the following two functions to encrypt data, bank details. i can
encrypt the details no problems. but when i try to decrypt the details i
get the following error
"PKCS7 padding is invalid and cannot be removed"
does anybody know i can encrypt and decrypt data from a database ? any
pointers would be greatfully appreciated!!
Many thanks
Simon Whale
P.S using vb.net 2003 and sql server 200
Public Function DecryptString(ByVal Value As String) As String
Dim ct As ICryptoTransform
Dim ms As MemoryStream
Dim cs As CryptoStream
Dim byt() As Byte
ct = mCSP.CreateDecryptor(mCSP.Key, mCSP.IV)
byt = Convert.FromBase64String(Value)
ms = New MemoryStream
cs = New CryptoStream(ms, ct, CryptoStreamMode.Write)
cs.Write(byt, 0, byt.Length)
cs.FlushFinalBlock()
cs.Close()
Return Encoding.UTF8.GetString(ms.ToArray())
End Function
Public Function EncryptString(ByVal Value As String) As String
Dim ct As ICryptoTransform
Dim ms As MemoryStream
Dim cs As CryptoStream
Dim byt() As Byte
ct = mCSP.CreateEncryptor(mCSP.Key, mCSP.IV)
byt = Encoding.UTF8.GetBytes(Value)
ms = New MemoryStream
cs = New CryptoStream(ms, ct, CryptoStreamMode.Write)
cs.Write(byt, 0, byt.Length)
cs.FlushFinalBlock()
cs.Close()
Return Convert.ToBase64String(ms.ToArray())
End Function
i am using the following two functions to encrypt data, bank details. i can
encrypt the details no problems. but when i try to decrypt the details i
get the following error
"PKCS7 padding is invalid and cannot be removed"
does anybody know i can encrypt and decrypt data from a database ? any
pointers would be greatfully appreciated!!
Many thanks
Simon Whale
P.S using vb.net 2003 and sql server 200
Public Function DecryptString(ByVal Value As String) As String
Dim ct As ICryptoTransform
Dim ms As MemoryStream
Dim cs As CryptoStream
Dim byt() As Byte
ct = mCSP.CreateDecryptor(mCSP.Key, mCSP.IV)
byt = Convert.FromBase64String(Value)
ms = New MemoryStream
cs = New CryptoStream(ms, ct, CryptoStreamMode.Write)
cs.Write(byt, 0, byt.Length)
cs.FlushFinalBlock()
cs.Close()
Return Encoding.UTF8.GetString(ms.ToArray())
End Function
Public Function EncryptString(ByVal Value As String) As String
Dim ct As ICryptoTransform
Dim ms As MemoryStream
Dim cs As CryptoStream
Dim byt() As Byte
ct = mCSP.CreateEncryptor(mCSP.Key, mCSP.IV)
byt = Encoding.UTF8.GetBytes(Value)
ms = New MemoryStream
cs = New CryptoStream(ms, ct, CryptoStreamMode.Write)
cs.Write(byt, 0, byt.Length)
cs.FlushFinalBlock()
cs.Close()
Return Convert.ToBase64String(ms.ToArray())
End Function