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 6382293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:30:15+00:00 2026-05-25T02:30:15+00:00

I’m fairly new encryption and decryption so please excuse my lack of knowledge in

  • 0

I’m fairly new encryption and decryption so please excuse my lack of knowledge in the subject.

I am trying to decrypt a string in Ruby. The string is read from a server where it was encrypted in PHP using MCRYPT_RIJNDAEL_128. I have the code to decrypt it in PHP which works and I’m trying to convert that to Ruby. I need this for authentication for the mobile application that I’m making using Rhodes (mobile application framework in Ruby).

Here is a snippet for the decryption at the PHP end.

  $key = "This is a test key";

  $string2 = hex2bin($string);  // The encrypted string   

  $iv = '1111F321414LOJL018473914DSADAS'; // Just given a random Initialisation vector for the example

  $encrypted = mcrypt_cbc(MCRYPT_RIJNDAEL_128, $key, $string2, MCRYPT_DECRYPT, $iv);

function hex2bin($str) {
    $bin = "";
    $i = 0;
     do {
       $bin .= chr(hexdec($str{$i}.$str{($i + 1)}));
       $i += 2;
       } while ($i < strlen($str));
    return $bin;
 }

hex2bin is a function that converts hexadecimal to binary.

So far here is my failed attempt to do this decryption using crpt:rijndael library provided by Ruby.

key = "This is a test key"
rd = Crypt::Rijndael.new(key, 128, 128)
string = @params['body'] // The encrypted string 
encrypted_string = hex2bin(string) 
decrypted_string = rd.decrypt_block(encrypted_string)

def hex2bin(str)
  bin = ""
  i = 0
  begin
    bin = bin + ((str[i]+str[i+1]).hex).chr
    i = i+2
  end while i<str.length
  return bin
end

I get an error saying that “App error: block must be 16 bytes long”. I tried adding the code to make it accept the initialisation vector from http://pastebin.com/m1rsJUXM. I still get the same error. Any sort of help or direction would be greatly appreciated.

Regards,

Ash

  • 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-25T02:30:16+00:00Added an answer on May 25, 2026 at 2:30 am

    Looking at your PHP code you seem to be using 128 bit Rijndael in CBC mode with an explicit IV and unspecified padding. Better to explicitly specify the padding, usually PKCS5 or PKCS7. Given that your error message is talking about one of your blocks not being 16 bytes long then I would be inclined to first suspect a problem with the padding. The last block of your plaintext may not have been padded to the next block boundary so it will be short of the required 16 bytes, hence the error message.

    Apart from that you need to ensure that you specify CBC mode in your Ruby code, so it matches the PHP code, and that the cyphertext, key and IV are identical at the byte level on both systems. Converting to and from strings can lead to differences and hence to problems. This is my second thought about your block size problem. If your conversion of the cyphertext from bytes to string and back to bytes again is changing the length of the cyphertext, then you will get the same error message.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
Specifically, suppose I start with the string string =hello \'i am \' me And

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.