Decrypt string using crypto

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

So, if you want to sign the value, I can use:

Crypto.sign(username); 

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

+6
source share
3 answers

The API is designed to create the SHA1 signature (as you can see in the code you are referring to). The purpose of this should not be reversible (unsigned), but should be used as authentication.

For example, if you signed an authentication token, you can verify that it was not tampered with by checking that Crypto.sign(token) == tokenSignature .

If you want to encrypt and decrypt, check Crypto.encryptAES / Crypto.decryptAES (added in Play 2.1).

+6
source

What exactly are you trying to do? You only sign the value to make sure that it has not been changed. The fact is that you cannot easily โ€œprintโ€ it.

If you want to encrypt and decrypt a value in your application, you need to use the encryption algorithm from javax.crypto .

+1
source

If you need encryption / decryption functions, you can try adding http://www.jasypt.org/ .

org.jasypt.util.text.BasicTextEncryptor allows the user to encrypt and decrypt text data using the normal strength algorithm. To be able to encrypt and decrypt.

How can you do something like this:

 ... BasicTextEncryptor textEncryptor = new BasicTextEncryptor(); textEncryptor.setPassword(myEncryptionPassword); ... String myEncryptedText = textEncryptor.encrypt(myText); String plainText = textEncryptor.decrypt(myEncryptedText); ... 
+1
source

Source: https://habr.com/ru/post/913150/


All Articles