login about faq


I have a Base64 encoded value that is AES CBC encrypted with a null IV. I tried all sorts of combinations, but the original string is not comming back. I can decrypt fine with AESManaged, but the target machine is Windows Server 2000, so we'll go for the Chilkat Chilkat.Crypt2 (It's a classic asp application).

This is what I have so far. (Key = "6F2F108EB7F65452A1EE3E5B007103ED" Testvalue = "Td6cGqFDvaKQes/ewPHX+Ygwl5IipdnyJf9hKiZbNv8="

unlocked = crypt.UnlockComponent("30-day trial")
if unlocked then
  crypt.CryptAlgorithm = "aes"
  crypt.CipherMode = "cbc"
  crypt.KeyLength = 128
  Dim iv: iv=HexStringToByteArray("0000000000000000")
  crypt.IV = iv 
  crypt.SecretKey =HexStringToByteArray(aeskey)
  Dim encryptedText: encryptedText = Base64Decode(encryptedBlock)
  numcard = ByteArrayToString(crypt.DecryptBytes(encryptedText))
  errorCode = 99
  errorText = "License Expired"
  numcard = ""
end if

Function hexStringToByteArray(s)
Dim r()
ReDim r(Len(s)/2-1)
Dim x
For i = 0 To  Len(s)-2 Step 2
    x= "&H" & Mid(s,i+1,2)
    r(i/2) = CInt(x)
hexStringToByteArray= r
End Function

function ByteArrayToString(theArray)
    dim i, str
    if vartype(theArray) < 8192 then
           exit function
    end if
    for i=lbound(theArray) to ubound(theArray) 
      str = str & asc(theArray(i))
    ByteArrayToString = str
end function

What am I doing wrong?

asked Oct 11 '13 at 06:03

Charly's gravatar image


edited Oct 11 '13 at 06:35

Your key is in hex, and the data you are trying to decrypt is the Base64 string representation of the encrypted bytes. Chilkat makes it easy to use the encoded strings directly, so you don't have to go through the pain and complexity of dealing with byte arrays.

With this solution, you can discard the functions for converting hex strings to byte arrays:

crypt.CryptAlgorithm = "aes"
crypt.CipherMode = "cbc"
crypt.KeyLength = 128
crypt.SetEncodedIV "0000000000000000", "hex"
crypt.SetEncodedKey "6F2F108EB7F65452A1EE3E5B007103ED", "hex"

crypt.EncodingMode = "base64"
dim outStr as String
outStr = crypt.DecryptStringENC("Td6cGqFDvaKQes/ewPHX+Ygwl5IipdnyJf9hKiZbNv8=")

Also, see this for a more detailed description of EncryptStringENC and DecryptStringENC: http://www.cknotes.com/?p=504 (The discussion at this web page pertains to any programming language)


answered Oct 11 '13 at 08:24

chilkat's gravatar image

chilkat ♦♦

Thank you very much for your fast and good reply! Very good service!

(Oct 11 '13 at 08:57) Charly
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported



Asked: Oct 11 '13 at 06:03

Seen: 3,897 times

Last updated: Oct 11 '13 at 08:57

powered by OSQA