RE: encryption help

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance




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
>
>
>
.



Relevant Pages

  • Search pattern
    ... Dim strfile As String ... Dim bAddressFound As Boolean ... Dim strCurrentChar As String ...
    (comp.databases.ms-access)
  • Auto Write Name and Merge across
    ... Dim Sheetname01 As String ... Dim WeekName01 As String ...
    (microsoft.public.excel.misc)
  • Re: multiplatform (pocketPC & desktopPC) (Daniel !!)
    ... Friend Versione As String ... Public Sub GetMyConnectionPalmare() ... Dim errorMessages As String ... Private Function GetDS_Desktop(ByVal SQL As String) As DataSet ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: multiplatform (pocketPC & desktopPC) (Daniel !!)
    ... Friend Versione As String ... Public Sub GetMyConnectionPalmare() ... Dim errorMessages As String ... Private Function GetDS_Desktop(ByVal SQL As String) As DataSet ...
    (microsoft.public.dotnet.framework.compactframework)
  • Help answer these 70-310 questions
    ... One argument is the string ... Dim output As New StringBuilder ... EmployeeLocations. ... You create a strongly named serviced component. ...
    (microsoft.public.cert.exam.mcsd)