RE: encryption help
- From: katzky <katzky@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 23 Nov 2005 08:59:07 -0800
Simon -
Well... I do not know for sure, since the provided code is incomplete, but i
believe that the problem has to do with the IV. The IV should be different
for every cipher text. This means that the IV needs to be known to the
function performing the decryption. It looks like your code:
ct = mCSP.CreateDecryptor(mCSP.Key, mCSP.IV)
generates a new IV during the decryption process [maybe? I dont really know
since mCSP is not defined in the code provided]
In applications I have written, the IV is included in the cipher text as
plaintext.
"Simon Whale" wrote:
> 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
>
>
>
.
- References:
- encryption help
- From: Simon Whale
- encryption help
- Prev by Date: Re: Business Layer
- Next by Date: Re: VS2005 Security Settings/Trust
- Previous by thread: encryption help
- Next by thread: .NET Framework 2.0
- Index(es):
Relevant Pages
|