Search in sources :

Example 1 with PSource

use of javax.crypto.spec.PSource in project jdk8u_jdk by JetBrains.

the class TestOAEPParameterSpec method comparePSource.

private static boolean comparePSource(OAEPParameterSpec s1, OAEPParameterSpec s2) {
    PSource src1 = s1.getPSource();
    PSource src2 = s2.getPSource();
    String alg1 = src1.getAlgorithm();
    String alg2 = src2.getAlgorithm();
    if (alg1.equals(alg2)) {
        // assumes they are PSource.PSpecified
        return Arrays.equals(((PSource.PSpecified) src1).getValue(), ((PSource.PSpecified) src2).getValue());
    } else {
        System.out.println("PSource algos: " + alg1 + " vs " + alg2);
        return false;
    }
}
Also used : PSource(javax.crypto.spec.PSource)

Example 2 with PSource

use of javax.crypto.spec.PSource in project robovm by robovm.

the class OAEPParameterSpecTest method testOAEPParameterSpec.

/**
     * OAEPParameterSpec(String mdName, String mgfName, AlgorithmParameterSpec
     * mgfSpec, PSource pSrc) method testing. Tests that NullPointerException
     * is thrown in the case of inappropriate constructor parameters and checks
     * the value of DEFAULT field.
     */
public void testOAEPParameterSpec() {
    // using init values for OAEPParameterSpec.DEFAULT
    String mdName = "SHA-1";
    String mgfName = "MGF1";
    AlgorithmParameterSpec mgfSpec = MGF1ParameterSpec.SHA1;
    PSource pSrc = PSource.PSpecified.DEFAULT;
    try {
        new OAEPParameterSpec(null, mgfName, mgfSpec, pSrc);
        fail("NullPointerException should be thrown in the case of " + "null mdName.");
    } catch (NullPointerException e) {
    }
    try {
        new OAEPParameterSpec(mdName, null, mgfSpec, pSrc);
        fail("NullPointerException should be thrown in the case of " + "null mgfName.");
    } catch (NullPointerException e) {
    }
    try {
        new OAEPParameterSpec(mdName, mgfName, mgfSpec, null);
        fail("NullPointerException should be thrown in the case of " + "null pSrc.");
    } catch (NullPointerException e) {
    }
    assertTrue("The message digest algorithm name of " + "OAEPParameterSpec.DEFAULT field should be " + mdName, OAEPParameterSpec.DEFAULT.getDigestAlgorithm().equals(mdName));
    assertTrue("The mask generation function algorithm name of " + "OAEPParameterSpec.DEFAULT field should be " + mgfName, OAEPParameterSpec.DEFAULT.getMGFAlgorithm().equals(mgfName));
    assertTrue("The mask generation function parameters of " + "OAEPParameterSpec.DEFAULT field should be the same object " + "as MGF1ParameterSpec.SHA1", OAEPParameterSpec.DEFAULT.getMGFParameters() == MGF1ParameterSpec.SHA1);
    assertTrue("The source of the encoding input P of " + "OAEPParameterSpec.DEFAULT field should be the same object " + "PSource.PSpecified.DEFAULT", OAEPParameterSpec.DEFAULT.getPSource() == PSource.PSpecified.DEFAULT);
}
Also used : PSource(javax.crypto.spec.PSource) AlgorithmParameterSpec(java.security.spec.AlgorithmParameterSpec) OAEPParameterSpec(javax.crypto.spec.OAEPParameterSpec)

Example 3 with PSource

use of javax.crypto.spec.PSource in project robovm by robovm.

the class OAEPParameterSpecTest method testGetMGFAlgorithm.

/**
     * getMGFAlgorithm() method testing.
     */
public void testGetMGFAlgorithm() {
    String mdName = "SHA-1";
    String mgfName = "MGF1";
    AlgorithmParameterSpec mgfSpec = MGF1ParameterSpec.SHA1;
    PSource pSrc = PSource.PSpecified.DEFAULT;
    OAEPParameterSpec ps = new OAEPParameterSpec(mdName, mgfName, mgfSpec, pSrc);
    assertTrue("The returned value does not equal to the " + "value specified in the constructor.", ps.getMGFAlgorithm().equals(mgfName));
}
Also used : PSource(javax.crypto.spec.PSource) AlgorithmParameterSpec(java.security.spec.AlgorithmParameterSpec) OAEPParameterSpec(javax.crypto.spec.OAEPParameterSpec)

Example 4 with PSource

use of javax.crypto.spec.PSource in project santuario-java by apache.

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 5 with PSource

use of javax.crypto.spec.PSource in project j2objc by google.

the class OAEPParameterSpecTest method testOAEPParameterSpec.

/**
 * OAEPParameterSpec(String mdName, String mgfName, AlgorithmParameterSpec
 * mgfSpec, PSource pSrc) method testing. Tests that NullPointerException
 * is thrown in the case of inappropriate constructor parameters and checks
 * the value of DEFAULT field.
 */
public void testOAEPParameterSpec() {
    // using init values for OAEPParameterSpec.DEFAULT
    String mdName = "SHA-1";
    String mgfName = "MGF1";
    AlgorithmParameterSpec mgfSpec = MGF1ParameterSpec.SHA1;
    PSource pSrc = PSource.PSpecified.DEFAULT;
    try {
        new OAEPParameterSpec(null, mgfName, mgfSpec, pSrc);
        fail("NullPointerException should be thrown in the case of " + "null mdName.");
    } catch (NullPointerException e) {
    }
    try {
        new OAEPParameterSpec(mdName, null, mgfSpec, pSrc);
        fail("NullPointerException should be thrown in the case of " + "null mgfName.");
    } catch (NullPointerException e) {
    }
    try {
        new OAEPParameterSpec(mdName, mgfName, mgfSpec, null);
        fail("NullPointerException should be thrown in the case of " + "null pSrc.");
    } catch (NullPointerException e) {
    }
    assertTrue("The message digest algorithm name of " + "OAEPParameterSpec.DEFAULT field should be " + mdName, OAEPParameterSpec.DEFAULT.getDigestAlgorithm().equals(mdName));
    assertTrue("The mask generation function algorithm name of " + "OAEPParameterSpec.DEFAULT field should be " + mgfName, OAEPParameterSpec.DEFAULT.getMGFAlgorithm().equals(mgfName));
    assertTrue("The mask generation function parameters of " + "OAEPParameterSpec.DEFAULT field should be the same object " + "as MGF1ParameterSpec.SHA1", OAEPParameterSpec.DEFAULT.getMGFParameters() == MGF1ParameterSpec.SHA1);
    assertTrue("The source of the encoding input P of " + "OAEPParameterSpec.DEFAULT field should be the same object " + "PSource.PSpecified.DEFAULT", OAEPParameterSpec.DEFAULT.getPSource() == PSource.PSpecified.DEFAULT);
}
Also used : PSource(javax.crypto.spec.PSource) AlgorithmParameterSpec(java.security.spec.AlgorithmParameterSpec) OAEPParameterSpec(javax.crypto.spec.OAEPParameterSpec)

Aggregations

PSource (javax.crypto.spec.PSource)20 OAEPParameterSpec (javax.crypto.spec.OAEPParameterSpec)17 AlgorithmParameterSpec (java.security.spec.AlgorithmParameterSpec)13 MGF1ParameterSpec (java.security.spec.MGF1ParameterSpec)7 InvalidParameterSpecException (java.security.spec.InvalidParameterSpecException)2 X509Certificate (java.security.cert.X509Certificate)1 ArrayList (java.util.ArrayList)1 Cipher (javax.crypto.Cipher)1 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)1 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)1 XMLSecurityException (org.apache.xml.security.exceptions.XMLSecurityException)1 XMLSecAttribute (org.apache.xml.security.stax.ext.stax.XMLSecAttribute)1 OutboundSecurityToken (org.apache.xml.security.stax.securityToken.OutboundSecurityToken)1 SecurityTokenConstants (org.apache.xml.security.stax.securityToken.SecurityTokenConstants)1