Search in sources :

Example 1 with DecryptionException

use of org.apereo.cas.util.crypto.DecryptionException in project cas by apereo.

the class SamlIdPObjectEncrypter method decode.

/**
 * Decode name id.
 *
 * @param encryptedId the encrypted id
 * @param service     the service
 * @param adaptor     the adaptor
 * @return the name id
 */
public NameID decode(final EncryptedID encryptedId, final SamlRegisteredService service, final SamlRegisteredServiceServiceProviderMetadataFacade adaptor) {
    try {
        Security.addProvider(new BouncyCastleProvider());
        val config = configureDecryptionSecurityConfiguration(service);
        configureKeyDecryptionCredential(adaptor.getEntityId(), adaptor, service, config);
        val parameters = resolveDecryptionParameters(service, config);
        val decrypter = getDecrypter(encryptedId, service, adaptor, parameters);
        return (NameID) decrypter.decrypt(encryptedId);
    } catch (final Exception e) {
        throw new DecryptionException(e);
    }
}
Also used : lombok.val(lombok.val) NameID(org.opensaml.saml.saml2.core.NameID) DecryptionException(org.apereo.cas.util.crypto.DecryptionException) SamlException(org.apereo.cas.support.saml.SamlException) ResolverException(net.shibboleth.utilities.java.support.resolver.ResolverException) DecryptionException(org.apereo.cas.util.crypto.DecryptionException) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider)

Example 2 with DecryptionException

use of org.apereo.cas.util.crypto.DecryptionException in project cas by apereo.

the class BaseBinaryCipherExecutor method decode.

@Override
public byte[] decode(final byte[] value, final Object[] parameters) {
    try {
        val verifiedValue = verifySignature(value, getSigningKey());
        val aesCipher = Cipher.getInstance(CIPHER_ALGORITHM);
        aesCipher.init(Cipher.DECRYPT_MODE, this.encryptionKey, this.parameterSpec);
        return aesCipher.doFinal(verifiedValue);
    } catch (final Exception e) {
        throw LOGGER.isTraceEnabled() ? new DecryptionException(e) : new DecryptionException();
    }
}
Also used : lombok.val(lombok.val) DecryptionException(org.apereo.cas.util.crypto.DecryptionException) DecryptionException(org.apereo.cas.util.crypto.DecryptionException)

Example 3 with DecryptionException

use of org.apereo.cas.util.crypto.DecryptionException in project cas by apereo.

the class EncodingUtils method decryptJwtValue.

/**
 * Decrypt value based on the key created.
 *
 * @param secretKeyEncryptionKey the secret key encryption key
 * @param value                  the value
 * @return the decrypted value
 */
public static String decryptJwtValue(final Key secretKeyEncryptionKey, final String value) {
    try {
        val jwe = new JsonWebEncryption();
        jwe.setKey(secretKeyEncryptionKey);
        jwe.setCompactSerialization(value);
        LOGGER.trace("Decrypting value...");
        return jwe.getPayload();
    } catch (final Exception e) {
        if (LOGGER.isTraceEnabled()) {
            throw new DecryptionException(e);
        }
        throw new DecryptionException();
    }
}
Also used : lombok.val(lombok.val) JsonWebEncryption(org.jose4j.jwe.JsonWebEncryption) DecryptionException(org.apereo.cas.util.crypto.DecryptionException) DecryptionException(org.apereo.cas.util.crypto.DecryptionException)

Aggregations

lombok.val (lombok.val)3 DecryptionException (org.apereo.cas.util.crypto.DecryptionException)3 ResolverException (net.shibboleth.utilities.java.support.resolver.ResolverException)1 SamlException (org.apereo.cas.support.saml.SamlException)1 BouncyCastleProvider (org.bouncycastle.jce.provider.BouncyCastleProvider)1 JsonWebEncryption (org.jose4j.jwe.JsonWebEncryption)1 NameID (org.opensaml.saml.saml2.core.NameID)1