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

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

Introduction

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

Prototype

ByteSource encrypt(byte[] raw, byte[] encryptionKey) throws CryptoException;

Source Link

Document

Encrypts data via the specified cipher key.

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. j a v a  2 s .com*/
        };
        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();
}

From source file:juzu.plugin.shiro.impl.common.RememberMeUtil.java

License:Open Source License

private static byte[] encrypt(byte[] serialized) {
    byte[] value = serialized;
    CipherService cipherService = new AesCipherService();
    if (cipherService != null) {
        ByteSource byteSource = cipherService.encrypt(serialized, Base64.decode("kPH+bIxk5D2deZiIxcaaaA=="));
        value = byteSource.getBytes();//from   w ww  .ja  va2s . c o  m
    }
    return value;
}

From source file:org.apache.camel.component.shiro.security.ShiroSecurityHelper.java

License:Apache License

public static ByteSource encrypt(ShiroSecurityToken securityToken, byte[] passPhrase,
        CipherService cipherService) throws Exception {
    ByteArrayOutputStream stream = new ByteArrayOutputStream();
    ObjectOutput serialStream = new ObjectOutputStream(stream);
    try {//from   www  .  j a va  2s  .  co m
        serialStream.writeObject(securityToken);
        return cipherService.encrypt(stream.toByteArray(), passPhrase);
    } finally {
        close(serialStream);
        IOHelper.close(stream);
    }
}