Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decrypt String with Crypto

the Play Framework 2.0 provides the lib Crypto, see code: https://github.com/playframework/Play20/blob/master/framework/src/play/src/main/scala/play/api/libs/Crypto.scala

So If want to sign a value I can use:

Crypto.sign(username);

But how to decrypt the username again? There is not method unsign or decrypt? Or am I missing something here?

like image 960
adis Avatar asked Apr 13 '12 17:04

adis


People also ask

How do I decrypt an encrypted string?

Given encrypted string str, the task is to decrypt the given string when the encryption rules are as follows: Start with the first character of the original string. In every odd step, append the next character to it. In every even step, prepend the next character to the encrypted string so far.

How do you encrypt and decrypt data in node js using crypto?

Encrypt and decrypt text const { encrypt, decrypt } = require('./crypto') const hash = encrypt('Hello World! ') console. log(hash) // { // iv: '237f306841bd23a418878792252ff6c8', // content: 'e2da5c6073dd978991d8c7cd' // } const text = decrypt(hash) console. log(text) // Hello World!

How do I encrypt and decrypt a string in node?

Using Clean architecture for Node.NodeJS provides inbuilt library crypto to encrypt and decrypt data in NodeJS. We can use this library to encrypt data of any type. You can do the cryptographic operations on a string, buffer, and even a stream of data. The crypto also holds multiple crypto algorithms for encryption.

What is string crypto?

StringEncrypt page allows you to encrypt strings and files using randomly generated algorithm, generating a unique decryption code in the selected programming language.


2 Answers

The API is for creating a signature, a SHA1 hash (as you can see in the code you link to). The purpose of that is not to be reversible (unsigned) but to be used as verification of authenticity.

For example, if you have signed an authentication token, you can make sure that it had not been tampered with by checking that Crypto.sign(token) == tokenSignature.

If you want encryption and decryption, check out Crypto.encryptAES/Crypto.decryptAES (added in Play 2.1).

like image 188
Pere Villega Avatar answered Sep 23 '22 02:09

Pere Villega


What exactly are you trying to do? You only sign a value to ensure that it wasn't altered. The point is that you cannot "unsign" it easily.

If you want to encrypt and decrypt a value within your app, you have to use an encryption algorithm from javax.crypto.

like image 22
Marius Soutier Avatar answered Sep 24 '22 02:09

Marius Soutier