Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6705885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:27:21+00:00 2026-05-26T07:27:21+00:00

I need to decrypt a base64 encoded binary in string format [0-9a-zA-Z+/]. Part of

  • 0

I need to decrypt a base64 encoded binary in string format [0-9a-zA-Z+/]. Part of this string consists of the ivSalt, which is the first 16 Bytes, or 128bits. The rest is data; everything was encrypted using AES with 128 key and in 128 CBC blocks and PKCS7Padding.

First the string needs to converted to binary:

<cfset b64 = ToBinary(enc)/>

Then we create a java byte buffer:

<cfset objByteBuffer = CreateObject(
  "java",
  "java.nio.ByteBuffer") />

Then we initialize a buffer for the salt and a buffer for the data that needs to be decrypted.

<cfset objBufferA = objByteBuffer.Allocate(
  JavaCast( "int", 16 )) />

<cfset objBufferB = objByteBuffer.Allocate(  
  JavaCast( "int", (Len(b64)-16) )) />

Then we fill the buffers with our bytes.

<cfset objBufferA.Put(
  b64,
  JavaCast( "int", 0 ),
  JavaCast( "int", 16 )) />

<cfset objBufferB.Put(
  b64,
  JavaCast( "int", 16 ),
  JavaCast( "int", (Len(b64)-16) )) />

<cfset ivStringBin = objBufferA.Array()/>
<cfset dataStringBin = objBufferB.Array()/>

Because the decrypt function takes a hexadecimal string we need to encode it to hex.

<!--- create byteArray output stream --->
<cfset baos = createObject("java", "java.io.ByteArrayOutputStream")>
<!--- write the byteArray stored in the DB to the output stream --->
<cfset baos.write(ivStringBin)>
<!--- convert binary content to text string --->
<cfset ivString=BinaryEncode(baos.toByteArray(),"hex")/>

<!--- create byteArray output stream --->
<cfset baos2 = createObject("java", "java.io.ByteArrayOutputStream")>
<!--- write the byteArray stored in the DB to the output stream --->
<cfset baos2.write(dataStringBin)>
<!--- convert binary content to text string --->  

<cfset dataString=BinaryEncode(baos2.toByteArray(),"hex")/>

Should be:

<cfset dataString=BinaryEncode(baos2.toByteArray(),"base64")/>

Now I’m not sure what to do with the key, but it appears to be required to be in a hexadecimal string format.

<cfset key = BinaryEncode(ToBinary("{16 chars, [0-9a-zA-Z+/]}")/>

Should be:

<cfset key = "{32 chars, [0-9A-Z]}"/>

ColdFusion doesn’t itself support PKCS7Padding with CBC, I get an unsupported provider error. So I go and install BouncyCastle and I found a wonderful ColdFusion example of how to decrypt with PKCS5Padding Un-encrypting / re-encrypting a ColdFusion encrypted string in PHP”>here. I added it to my code but I need PKCS7Padding so I changed

var zbPadding = CreateObject('java', 'org.bouncycastle.crypto.paddings.ZeroBytePadding').init();

to

var zbPadding = CreateObject('java', 'org.bouncycastle.crypto.paddings.PKCS7Padding').init();

according to the Bouncy Castle docs .

With all this I get the error:

"Key length not 128/160/192/224/256 bits."

I will be trying off and on but I am completely stuck, I can’t figure out what I am doing wrong.

Edit 1:

I got it working!

  • The dataString needed to be in base64 instead of hex.
  • The key, when converted to hex using coldFusion is 24 [0-9A-F] chars representing 24×4=96 bits which is 12 Bytes. It needs to be 16 Bytes, so somehow the BinaryEncode(ToBinary()) function doesn’t do its job. So I used a string to hex tool to convert it and then subsequently got 32 chars.

Edit 2:
Also, to install Bouncy Castle I followed the bouncy castle installe instructions and downloaded jce from the bottom of the java downloads page.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T07:27:22+00:00Added an answer on May 26, 2026 at 7:27 am

    I got it working!

    • The dataString needed to be in base64 instead of hex.

    • The key, when converted to hex using coldFusion is 24 [0-9A-F] chars representing 24×4=96 bits which is 12 Bytes. It needs to be 16 Bytes, so somehow the BinaryEncode(ToBinary()) function doesn’t do its job. So I used a string to hex tool to convert it and then subsequently got 32 chars.
      Edit 2: Also, to install Bouncy Castle I followed the bouncy castle installe instructions and downloaded jce from the bottom of the java downloads page.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a PHP script to decrypt the RSA encrypted string generated by this
I want to decrypt the string in base64 format. I have some data in
I need to save a db password as an encrypted string and then decrypt
I need to decrypt some data that has been 3des encoded on system running
I need fast and simple way to encrypt/decrypt a lot of String data. I
For a project I'm working on, I need to encrypt and decrypt a string
Ok, I have a string of text, encoded in Base64. I want to decode
In my current iPhone project I need to decrypt zip files which have been
I have an encrypted bit of text that I need to decrypt. It's encrypted
In my Python web app, I would need to decrypt a file that was

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.