Ruby hexdigest decrypt


















The encrypt function also requires secret key. This key is encoded with Base64 and added base as prefix. So the equivalent step in Ruby should be as follow:. Another note on why we need to encode encrypted value in Base64, it's not because of default options value in PHP but because often there is a good chance that encrypted value will contain byte char which is not supported by JSON. Then, we'll JSON the data into the "payload" array.

So the equivalent step in Ruby should be as follow: cipher. Just wondering, what's wrong about external gems? Add a comment. Active Oldest Votes. Graham Slick 6, 9 9 gold badges 45 45 silver badges 75 75 bronze badges. Joshua Cheek Joshua Cheek Thanks for your solution, though two very similar codes yield very similar encrypted results using your last solution Joshua Is there anyway to make your first example print out "regular" characters rather than gibberish?

I imagine it'll need some type of encoding and decoding. Sorry, I'm not a Ruby guy, but was asked to modify some old code that's still running on 1. I have no idea what you mean by "regular" characters and "giberish".

Every character in here is ASCII, are you getting some sort of unicode or you just don't want that particular set of characters? Note that you do not have to store iv - just send it with the encrypted message. You can also encrypt it for added security, but use a separate key! Note that if you use CBC and don't provide the iv, it sets iv to all zeroes, which is pretty iffy. Also note that the secret should probably be a large randomly generated string. Ari Ari 1, 19 19 silver badges 30 30 bronze badges.

Prashanth Sams Prashanth Sams Jignesh Gohel Jignesh Gohel 5, 4 4 gold badges 49 49 silver badges 85 85 bronze badges. I like this simple solution. I never really understodo base64 encoding. It looks like what's happening is that we're going from a string to another string but I thought base64 encoding went from a sequence of bytes to a text string. A string is a sequence of bytes.

An encoding is used for the string, e. UTF-8 and it determines the bytes that will be used to represent the code points of the string. It is not a way to encrypt stuff. It is crystal clear given a Base64 decoder. No encryption key involved.

Sorry I don't understand it. Could anyone make a further explanation or give a piece of sample code for it? Robert me neither.

I guess Philip answered his own question in order to demonstrate how smart he is. Technically this is crypto, the use case is unusual and non of the other answers satisfy the requirement. Answering your own question is not to show how smart you are but to provide answers to the community. So if you figure out a solution dont be selfish and keep it to yourself.

Nakilon I'm running ruby 2. The OS is Ubuntu I should also mention that this script works fine on an Ubuntu 17 machine with Ruby version ruby 2. In this gist, key is a cipher "password". You are trying to set the "encryption key". Consider using your key as cipher password and generate a secure random key.

Check out Ruby's documentation for encrypt and key and the section Choosing a key. I suggest, you don't use a password, but generate a secure random key. Store it somewhere safe, e. Skip to content. Sign in Sign up. Instantly share code, notes, and snippets. Last active Jan 8,



0コメント

  • 1000 / 1000