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?
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.
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!
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.
StringEncrypt page allows you to encrypt strings and files using randomly generated algorithm, generating a unique decryption code in the selected programming language.
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).
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With