Search in sources :

Example 1 with CipherService

use of org.apache.shiro.crypto.CipherService in project cas by apereo.

the class BaseBinaryCipherExecutor method encode.

@Override
public byte[] encode(final byte[] value) {
    try {
        final Key key = new SecretKeySpec(this.encryptionSecretKey.getBytes(StandardCharsets.UTF_8), this.secretKeyAlgorithm);
        final CipherService cipher = new AesCipherService();
        final byte[] result = cipher.encrypt(value, key.getEncoded()).getBytes();
        return sign(result);
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
        throw Throwables.propagate(e);
    }
}
Also used : AesCipherService(org.apache.shiro.crypto.AesCipherService) SecretKeySpec(javax.crypto.spec.SecretKeySpec) CipherService(org.apache.shiro.crypto.CipherService) AesCipherService(org.apache.shiro.crypto.AesCipherService) OctetSequenceJsonWebKey(org.jose4j.jwk.OctetSequenceJsonWebKey) JsonWebKey(org.jose4j.jwk.JsonWebKey) Key(java.security.Key)

Example 2 with CipherService

use of org.apache.shiro.crypto.CipherService in project cas by apereo.

the class BaseBinaryCipherExecutor method decode.

@Override
public byte[] decode(final byte[] value) {
    try {
        final byte[] verifiedValue = verifySignature(value);
        final Key key = new SecretKeySpec(this.encryptionSecretKey.getBytes(StandardCharsets.UTF_8), this.secretKeyAlgorithm);
        final CipherService cipher = new AesCipherService();
        final byte[] result = cipher.decrypt(verifiedValue, key.getEncoded()).getBytes();
        return result;
    } catch (final Exception e) {
        throw Throwables.propagate(e);
    }
}
Also used : AesCipherService(org.apache.shiro.crypto.AesCipherService) SecretKeySpec(javax.crypto.spec.SecretKeySpec) CipherService(org.apache.shiro.crypto.CipherService) AesCipherService(org.apache.shiro.crypto.AesCipherService) OctetSequenceJsonWebKey(org.jose4j.jwk.OctetSequenceJsonWebKey) JsonWebKey(org.jose4j.jwk.JsonWebKey) Key(java.security.Key)

Aggregations

Key (java.security.Key)2 SecretKeySpec (javax.crypto.spec.SecretKeySpec)2 AesCipherService (org.apache.shiro.crypto.AesCipherService)2 CipherService (org.apache.shiro.crypto.CipherService)2 JsonWebKey (org.jose4j.jwk.JsonWebKey)2 OctetSequenceJsonWebKey (org.jose4j.jwk.OctetSequenceJsonWebKey)2