Search in sources :

Example 21 with OAEPParameterSpec

use of javax.crypto.spec.OAEPParameterSpec in project Bytecoder by mirkosertic.

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 22 with OAEPParameterSpec

use of javax.crypto.spec.OAEPParameterSpec in project Bytecoder by mirkosertic.

the class RSACipher method engineInit.

// see JCE spec
protected void engineInit(int opmode, Key key, AlgorithmParameters params, SecureRandom random) throws InvalidKeyException, InvalidAlgorithmParameterException {
    if (params == null) {
        init(opmode, key, random, null);
    } else {
        try {
            OAEPParameterSpec spec = params.getParameterSpec(OAEPParameterSpec.class);
            init(opmode, key, random, spec);
        } catch (InvalidParameterSpecException ipse) {
            InvalidAlgorithmParameterException iape = new InvalidAlgorithmParameterException("Wrong parameter");
            iape.initCause(ipse);
            throw iape;
        }
    }
}
Also used : InvalidParameterSpecException(java.security.spec.InvalidParameterSpecException) OAEPParameterSpec(javax.crypto.spec.OAEPParameterSpec)

Example 23 with OAEPParameterSpec

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

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 24 with OAEPParameterSpec

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

the class OAEPParameterSpecTest method testGetDigestAlgorithm.

/**
 * getDigestAlgorithm() method testing.
 */
public void testGetDigestAlgorithm() {
    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.getDigestAlgorithm().equals(mdName));
}
Also used : PSource(javax.crypto.spec.PSource) AlgorithmParameterSpec(java.security.spec.AlgorithmParameterSpec) OAEPParameterSpec(javax.crypto.spec.OAEPParameterSpec)

Example 25 with OAEPParameterSpec

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

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)

Aggregations

OAEPParameterSpec (javax.crypto.spec.OAEPParameterSpec)34 PSource (javax.crypto.spec.PSource)19 AlgorithmParameterSpec (java.security.spec.AlgorithmParameterSpec)15 MGF1ParameterSpec (java.security.spec.MGF1ParameterSpec)11 Cipher (javax.crypto.Cipher)10 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)6 InvalidKeyException (java.security.InvalidKeyException)6 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)6 URISyntaxException (java.net.URISyntaxException)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)4 InvalidParameterSpecException (java.security.spec.InvalidParameterSpecException)4 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)4 AlgorithmParameters (java.security.AlgorithmParameters)3 XMLSecurityException (org.apache.xml.security.exceptions.XMLSecurityException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 URI (java.net.URI)2 InvalidParameterException (java.security.InvalidParameterException)2 Key (java.security.Key)2 NoSuchProviderException (java.security.NoSuchProviderException)2 SecureRandom (java.security.SecureRandom)2