Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why set a password using Jasypt when encrypting text?

To encrypt a password I use (modified from http://www.jasypt.org/encrypting-texts.html):

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

Why is a password required to be set on BasicTextEncryptor?

I may be not understanding something fundamental here but does this not make sense, although it does not work :

BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
String myEncryptedText = textEncryptor.encrypt(myText);
String plainText = textEncryptor.decrypt(myEncryptedText);
like image 709
blue-sky Avatar asked Dec 25 '22 17:12

blue-sky


1 Answers

It does work and it does require password for encryption and decryption. To simplify the example I have initiated two sessions of StandardPBEStringEncryptor as encryptor and decryptor

public static void main(String[] args) {
    StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
    encryptor.setPassword("mySecretPassword");        
    String encryptedText = encryptor.encrypt("Hello World");
    System.out.println("Encrypted text is: " + encryptedText);

    StandardPBEStringEncryptor decryptor = new StandardPBEStringEncryptor();
    decryptor.setPassword("mySecretPassword");  
    String decryptedText = decryptor.decrypt(encryptedText);
    System.out.println("Decrypted text is: " + decryptedText);
    }

output:

Encrypted text is: +pBbr+KOb7D6Ap/5vYJIUoHbhOruls+L
Decrypted text is: Hello World
like image 79
user3020494 Avatar answered Dec 28 '22 06:12

user3020494