Search in sources :

Example 11 with MGF1ParameterSpec

use of java.security.spec.MGF1ParameterSpec in project jdk8u_jdk by JetBrains.

the class OAEPParameters method engineInit.

protected void engineInit(AlgorithmParameterSpec paramSpec) throws InvalidParameterSpecException {
    if (!(paramSpec instanceof OAEPParameterSpec)) {
        throw new InvalidParameterSpecException("Inappropriate parameter specification");
    }
    OAEPParameterSpec spec = (OAEPParameterSpec) paramSpec;
    mdName = spec.getDigestAlgorithm();
    String mgfName = spec.getMGFAlgorithm();
    if (!mgfName.equalsIgnoreCase("MGF1")) {
        throw new InvalidParameterSpecException("Unsupported mgf " + mgfName + "; MGF1 only");
    }
    AlgorithmParameterSpec mgfSpec = spec.getMGFParameters();
    if (!(mgfSpec instanceof MGF1ParameterSpec)) {
        throw new InvalidParameterSpecException("Inappropriate mgf " + "parameters; non-null MGF1ParameterSpec only");
    }
    this.mgfSpec = (MGF1ParameterSpec) mgfSpec;
    PSource pSrc = spec.getPSource();
    if (pSrc.getAlgorithm().equals("PSpecified")) {
        p = ((PSource.PSpecified) pSrc).getValue();
    } else {
        throw new InvalidParameterSpecException("Unsupported pSource " + pSrc.getAlgorithm() + "; PSpecified only");
    }
}
Also used : InvalidParameterSpecException(java.security.spec.InvalidParameterSpecException) PSource(javax.crypto.spec.PSource) AlgorithmParameterSpec(java.security.spec.AlgorithmParameterSpec) OAEPParameterSpec(javax.crypto.spec.OAEPParameterSpec) MGF1ParameterSpec(java.security.spec.MGF1ParameterSpec)

Example 12 with MGF1ParameterSpec

use of java.security.spec.MGF1ParameterSpec in project jdk8u_jdk by JetBrains.

the class XMLCipher method constructOAEPParameters.

/**
     * Construct an OAEPParameterSpec object from the given parameters
     */
private OAEPParameterSpec constructOAEPParameters(String encryptionAlgorithm, String digestAlgorithm, String mgfAlgorithm, byte[] oaepParams) {
    if (XMLCipher.RSA_OAEP.equals(encryptionAlgorithm) || XMLCipher.RSA_OAEP_11.equals(encryptionAlgorithm)) {
        String jceDigestAlgorithm = "SHA-1";
        if (digestAlgorithm != null) {
            jceDigestAlgorithm = JCEMapper.translateURItoJCEID(digestAlgorithm);
        }
        PSource.PSpecified pSource = PSource.PSpecified.DEFAULT;
        if (oaepParams != null) {
            pSource = new PSource.PSpecified(oaepParams);
        }
        MGF1ParameterSpec mgfParameterSpec = new MGF1ParameterSpec("SHA-1");
        if (XMLCipher.RSA_OAEP_11.equals(encryptionAlgorithm)) {
            if (EncryptionConstants.MGF1_SHA256.equals(mgfAlgorithm)) {
                mgfParameterSpec = new MGF1ParameterSpec("SHA-256");
            } else if (EncryptionConstants.MGF1_SHA384.equals(mgfAlgorithm)) {
                mgfParameterSpec = new MGF1ParameterSpec("SHA-384");
            } else if (EncryptionConstants.MGF1_SHA512.equals(mgfAlgorithm)) {
                mgfParameterSpec = new MGF1ParameterSpec("SHA-512");
            }
        }
        return new OAEPParameterSpec(jceDigestAlgorithm, "MGF1", mgfParameterSpec, pSource);
    }
    return null;
}
Also used : PSource(javax.crypto.spec.PSource) MGF1ParameterSpec(java.security.spec.MGF1ParameterSpec) OAEPParameterSpec(javax.crypto.spec.OAEPParameterSpec)

Example 13 with MGF1ParameterSpec

use of java.security.spec.MGF1ParameterSpec in project jdk8u_jdk by JetBrains.

the class TestOAEPParameterSpec method compareMGF.

private static boolean compareMGF(OAEPParameterSpec s1, OAEPParameterSpec s2) {
    String alg1 = s1.getMGFAlgorithm();
    String alg2 = s2.getMGFAlgorithm();
    if (alg1.equals(alg2)) {
        MGF1ParameterSpec mp1 = (MGF1ParameterSpec) s1.getMGFParameters();
        MGF1ParameterSpec mp2 = (MGF1ParameterSpec) s2.getMGFParameters();
        alg1 = mp1.getDigestAlgorithm();
        alg2 = mp2.getDigestAlgorithm();
        if (alg1.equals(alg2)) {
            return true;
        } else {
            System.out.println("MGF's MD algos: " + alg1 + " vs " + alg2);
            return false;
        }
    } else {
        System.out.println("MGF algos: " + alg1 + " vs " + alg2);
        return false;
    }
}
Also used : MGF1ParameterSpec(java.security.spec.MGF1ParameterSpec)

Aggregations

MGF1ParameterSpec (java.security.spec.MGF1ParameterSpec)13 OAEPParameterSpec (javax.crypto.spec.OAEPParameterSpec)4 Digest (org.bouncycastle.crypto.Digest)4 OAEPEncoding (org.bouncycastle.crypto.encodings.OAEPEncoding)4 RSABlindedEngine (org.bouncycastle.crypto.engines.RSABlindedEngine)4 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)2 InvalidKeyException (java.security.InvalidKeyException)2 InvalidParameterException (java.security.InvalidParameterException)2 SecureRandom (java.security.SecureRandom)2 RSAPrivateKey (java.security.interfaces.RSAPrivateKey)2 RSAPublicKey (java.security.interfaces.RSAPublicKey)2 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)2 PSource (javax.crypto.spec.PSource)2 CipherParameters (org.bouncycastle.crypto.CipherParameters)2 ParametersWithRandom (org.bouncycastle.crypto.params.ParametersWithRandom)2 SignatureAlgorithm (io.jsonwebtoken.SignatureAlgorithm)1 AlgorithmParameterSpec (java.security.spec.AlgorithmParameterSpec)1 InvalidParameterSpecException (java.security.spec.InvalidParameterSpecException)1 PSSParameterSpec (java.security.spec.PSSParameterSpec)1 HashMap (java.util.HashMap)1