Symmetric key encryption for javascript and ruby

I want to encode a number that should be a maximum of 10 digits with a key with ASCII characters.

The encoded string must be decoded using the same key that the decoded number should return.

10 => encoding_with("secret_pass") => hash => decoding_with("secret_pass") => 10 

Both operations should work the same in Javascript and Ruby.

What algorithm should I use for this purpose?

All data must be in ASCII, not contain multibyte data for input, hashing and key.

+4
source share
3 answers

A simple XOR should be sufficient.

Javascript

Ruby

Yes, you can go overboard and snatch a full set of cryptos, but since one part of the algorithm will be launched in the browser, in JS (completely unreliable environment) any attempt by Serious Cryptography ™ will give you a false sense of security (in other words, your system is actually less safe).

If you are trying to protect data in transit, use the tool created for the job; in this case, https.

+4
source

I would like to learn some of Symmetric Key Encryption , as well as the most famous AES. AES is pretty much the standard and is implemented in both languages. Just be sure to use the same key and salt for encryption and decryption.

Javascript AES

Ruby AES

+2
source

If you want it to be simple and security is not a big concern (since Javascript ... observation in the comments), the easiest way would be to simply create any random value larger (more digits) than the number and a simple XOR with number. It is assumed that the key (= random number) will be previously transferred to another program.

 1. generate random number with 10 hex digits -> KEY 2. take the number then do (number XOR key ) -> result 3. send result 4. get the result and do (result XOR key) -> number 

something better (stronger) would be to use any system of public and private keys. The exchange keys, crypts with the public on one side, are decrypted with closed keys on the other side.

+1
source

All Articles