views:

909

answers:

2

I need to encrypt a integer, but all the crypto libraries only support strings.

What is the proper method to convert a integer to a binary string in Ruby? (not '10111', I think that it's ASCII values)

EDIT: I wasn't thinking about Rijndael as stream encryption.

+1  A: 

Stream encryption algorithms work on streams -- a sequence of characters. It is upto you to treat is as an integer or a newline.

Rijndael (a block cipher) will happily accept a non-128 bit string (stream, if you will) and padd the end with 0s. Check out the documentation and give it a shot.

dirkgently
I'm using Rijndael (AES) with the Crypt gem
Titanous
A: 
irb(main):007:0> [65,66].pack 'C*'
=> "AB"
Nakilon