Search in sources :

Example 6 with PSource

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

the class OAEPParameterSpecTest method testGetMGFParameters.

/**
     * getMGFParameters() method testing.
     */
public void testGetMGFParameters() {
    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.getMGFParameters() == mgfSpec);
}
Also used : PSource(javax.crypto.spec.PSource) AlgorithmParameterSpec(java.security.spec.AlgorithmParameterSpec) OAEPParameterSpec(javax.crypto.spec.OAEPParameterSpec)

Example 7 with PSource

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

the class OAEPParameterSpecTest method testGetPSource.

/**
     * getPSource() method testing.
     */
public void testGetPSource() {
    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.getPSource() == pSrc);
}
Also used : PSource(javax.crypto.spec.PSource) AlgorithmParameterSpec(java.security.spec.AlgorithmParameterSpec) OAEPParameterSpec(javax.crypto.spec.OAEPParameterSpec)

Example 8 with PSource

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

the class PSourceTest method testGetAlgorithm.

/**
     * getAlgorithm() method testing. Tests that returned value is
     * equal to the value specified in the constructor.
     */
public void testGetAlgorithm() {
    String pSrcName = "pSrcName";
    PSource ps = new PSource(pSrcName) {
    };
    assertTrue("The returned value is not equal to the value specified " + "in constructor", pSrcName.equals(ps.getAlgorithm()));
}
Also used : PSource(javax.crypto.spec.PSource)

Example 9 with PSource

use of javax.crypto.spec.PSource 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 10 with PSource

use of javax.crypto.spec.PSource 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)

Aggregations

PSource (javax.crypto.spec.PSource)10 OAEPParameterSpec (javax.crypto.spec.OAEPParameterSpec)8 AlgorithmParameterSpec (java.security.spec.AlgorithmParameterSpec)6 MGF1ParameterSpec (java.security.spec.MGF1ParameterSpec)3 InvalidParameterSpecException (java.security.spec.InvalidParameterSpecException)1