Java Code Examples for org.springframework.security.crypto.encrypt.TextEncryptor#decrypt()

The following examples show how to use org.springframework.security.crypto.encrypt.TextEncryptor#decrypt() . 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: EncryptionComponent.java    From syndesis with Apache License 2.0 6 votes vote down vote up
public String decrypt(final String value) {
    // value might not be encrypted...
    if( value == null ) {
        return null;
    }
    String result = value;
    if( result.startsWith(ENCRYPTED_PREFIX)) {
        TextEncryptor enc = textEncryptor;
        try {
            result = enc.decrypt(stripPrefix(result, ENCRYPTED_PREFIX));
        } catch (RuntimeException e) {
            // We could fail to decrypt the value..
            throw new KException(e);
        }
    }
    return result;
}
 
Example 2
Source File: EncryptionController.java    From spring-cloud-config with Apache License 2.0 6 votes vote down vote up
@RequestMapping(value = "/decrypt/{name}/{profiles}", method = RequestMethod.POST)
public String decrypt(@PathVariable String name, @PathVariable String profiles,
		@RequestBody String data, @RequestHeader("Content-Type") MediaType type) {
	TextEncryptor encryptor = getEncryptor(name, profiles, "");
	checkDecryptionPossible(encryptor);
	validateEncryptionWeakness(encryptor);
	try {
		encryptor = getEncryptor(name, profiles, data);
		String input = stripFormData(helper.stripPrefix(data), type, true);
		String decrypted = encryptor.decrypt(input);
		logger.info("Decrypted cipher data");
		return decrypted;
	}
	catch (IllegalArgumentException | IllegalStateException e) {
		logger.error("Cannot decrypt key:" + name + ", value:" + data, e);
		throw new InvalidCipherException();
	}
}
 
Example 3
Source File: CryptoUtilsTest.java    From zhcet-web with Apache License 2.0 5 votes vote down vote up
@Test
public void testStandardTextEncryptor() {
    TextEncryptor textEncryptor = CryptoUtils.getStandardEncryptor("newPassword");

    String dataToBeEncrypted = "This is a String data to be encrypted";
    String encryptedData = textEncryptor.encrypt(dataToBeEncrypted);

    assertNotNull(encryptedData);

    String decryptedData = textEncryptor.decrypt(encryptedData);

    assertNotNull(decryptedData);
    assertEquals(dataToBeEncrypted, decryptedData);
}
 
Example 4
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 5
Source File: CryptoResource.java    From flair-engine with Apache License 2.0 4 votes vote down vote up
@PostMapping("/decrypt")
public String decrypt(@RequestBody String cipherData) {
    final SymmetricEncryptionFactory symEncFactory = cryptoAbstractFactory.getSymEncFactory();
    final TextEncryptor textEncryptor = symEncFactory.getSymmetricTextEncryption(keyManager.getDatabaseEncryptionKey());
    return textEncryptor.decrypt(cipherData);
}
 
Example 6
Source File: AbstractConverter.java    From blog with Apache License 2.0 4 votes vote down vote up
private T decrypt(TextEncryptor encryptor, String attributeString) {
    String decryptedAttributeString = encryptor.decrypt(attributeString);
    return stringToEntityAttribute(decryptedAttributeString);
}