login about faq

We have the following situation. We need to AES decrypt from a base64 string, where the base64 (if decoded) is composed of the IV followed by the encrypted bytes. How can this be done simply?

asked Apr 26 at 15:53

chilkat's gravatar image

chilkat ♦♦
11.8k316358420


The IV for AES is always 16 bytes in length. (The IV for any block encryption algorithm is always equal to the block size as defined by the algorithm. For AES, the block size is 16 bytes, regardless of key size.)

The simplest way to solve the problem is to use the Crypt2.ReEncode method to re-encode the input string from Base64 to Hex. This way, you can easily split the string into it's two parts: the IV and the encrypted data.

For example, in VBScript:

encryptedHex = crypt.ReEncode(encryptedBase64,"base64","hex")

Once you have the string in hex form, it is easy to split. The IV is the first 32 chars (each byte in a hex string is represented by 2 chars. For example, the hex string 01020304 represents 4 bytes: 1,2,3,4.) So.. write code to split the string, then:

  1. Set the IV by calling Crypt2.SetEncodedIV(ivHexStr,"hex")
  2. Set the Crypt2.EncodingMode = "hex"
  3. Decrypt by calling DecryptStringENC(encHexStr)
link

answered Apr 26 at 15:59

chilkat's gravatar image

chilkat ♦♦
11.8k316358420

Your answer
toggle preview

Follow this question

By Email:

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

By RSS:

Answers

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

Tags:

×33
×13
×2
×1

Asked: Apr 26 at 15:53

Seen: 346 times

Last updated: Apr 26 at 15:59

powered by OSQA