Example usage for org.apache.shiro.crypto CipherService decrypt

List of usage examples for org.apache.shiro.crypto CipherService decrypt

Introduction

In this page you can find the example usage for org.apache.shiro.crypto CipherService decrypt.

Prototype

ByteSource decrypt(byte[] encrypted, byte[] decryptionKey) throws CryptoException;

Source Link

Document

Decrypts encrypted data via the specified cipher key and returns the original (pre-encrypted) data.

Usage

From source file:co.runrightfast.core.security.crypto.impl.EncryptionServiceImpl.java

License:Apache License

private Map<String, CipherFunctions> cipherFunctions(@NonNull final CipherService cipherService,
        final Map<String, Key> secretKeys) {
    final ImmutableMap.Builder<String, CipherFunctions> map = ImmutableMap.builder();
    secretKeys.entrySet().stream().forEach(entry -> {
        final byte[] secretKey = entry.getValue().getEncoded();
        final Encryption encryption = data -> {
            try {
                return cipherService.encrypt(data, secretKey).getBytes();
            } catch (final Exception e) {
                throw new EncryptionServiceException(e);
            }//  w  w  w .ja v  a 2s  .c  o m
        };
        final Decryption decryption = data -> {
            try {
                return cipherService.decrypt(data, secretKey).getBytes();
            } catch (final Exception e) {
                throw new EncryptionServiceException(e);
            }
        };
        map.put(entry.getKey(), new CipherFunctions(encryption, decryption));
    });

    return map.build();
}