Java Code Examples for org.springframework.security.crypto.encrypt.Encryptors#delux()

The following examples show how to use org.springframework.security.crypto.encrypt.Encryptors#delux() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StringEncryptorHolder.java    From summerframework with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {

        TextEncryptor encryptor =
            Encryptors.delux("pass", new String(Hex.encode("salt".getBytes(Charset.forName("utf-8")))));
        System.out.println(encryptor.encrypt("sadfsadfasfsadf"));
        System.out.println(encryptor.encrypt("sadfsadfasfsadf"));
        System.out.println(encryptor.decrypt(encryptor.encrypt("这是密码")));
    }
 
Example 2
Source File: EncryptionUtility.java    From blackduck-alert with Apache License 2.0 5 votes vote down vote up
public String encrypt(String value) {
    String password = getPassword();
    String salt = getEncodedSalt();
    if (StringUtils.isNotBlank(value) && StringUtils.isNotBlank(password) && StringUtils.isNotBlank(salt)) {
        TextEncryptor encryptor = Encryptors.delux(password, salt);
        return encryptor.encrypt(value);
    }
    return StringUtils.EMPTY;
}
 
Example 3
Source File: EncryptionUtility.java    From blackduck-alert with Apache License 2.0 5 votes vote down vote up
public String decrypt(String encryptedValue) {
    try {
        String password = getPassword();
        String salt = getEncodedSalt();
        if (StringUtils.isNotBlank(encryptedValue) && StringUtils.isNotBlank(password) && StringUtils.isNotBlank(salt)) {
            TextEncryptor decryptor = Encryptors.delux(password, salt);
            return decryptor.decrypt(encryptedValue);
        }
    } catch (IllegalArgumentException | IllegalStateException | NullPointerException ex) {
        logger.error("Error decrypting value", ex);
    }
    return StringUtils.EMPTY;
}
 
Example 4
Source File: AesGcmPasswordEncoder.java    From airsonic-advanced with GNU General Public License v3.0 4 votes vote down vote up
public AesGcmPasswordEncoder(String password, String salt) {
    this.encryptor = Encryptors.delux(password, salt);
}
 
Example 5
Source File: StrongStringEncryptor.java    From summerframework with Apache License 2.0 4 votes vote down vote up
public StrongStringEncryptor(String password, String salt) {
    super(password, salt);
    encryptor = Encryptors.delux(super.getPassword(), super.getSalt());
}
 
Example 6
Source File: CryptoUtils.java    From zhcet-web with Apache License 2.0 2 votes vote down vote up
/**
 * Gets a standard data encryptor to be used within application
 *
 * Subject to discussion with peers about which fields should be used as password. Pepper is used as salt
 * Once the field is encrypted, it can't be decrypted if the internal logic of the function is changed,
 * Thus, it is very important to use the function judiciously
 *
 * If the function logic seems insecure or inadequate, you may create your own Encryptor.
 * For future proof encryption decryption, use the methods instead of the encryptor returned
 *
 * @param password String to be used as password
 * @return A text encryptor
 */
public static TextEncryptor getStandardEncryptor(String password) {
    String salt = Hex.encodeHexString(PEPPER.getBytes());
    return Encryptors.delux(PEPPER + password + PEPPER, salt);
}