javax.crypto.spec.PSource Java Examples

The following examples show how to use javax.crypto.spec.PSource. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestOAEPParameterSpec.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static boolean runTest(String mdName, MGF1ParameterSpec mgfSpec,
    byte[] p) throws Exception {
    OAEPParameterSpec spec = new OAEPParameterSpec(mdName, "MGF1",
        mgfSpec, new PSource.PSpecified(p));
    cp = Security.getProvider("SunJCE");
    System.out.println("Testing provider " + cp.getName() + "...");
    AlgorithmParameters ap = AlgorithmParameters.getInstance("OAEP", cp);

    ap.init(spec);
    byte[] encoding = ap.getEncoded();

    AlgorithmParameters ap2 = AlgorithmParameters.getInstance("OAEP", cp);
    ap2.init(encoding);

    OAEPParameterSpec spec2 = (OAEPParameterSpec) ap2.getParameterSpec
            (OAEPParameterSpec.class);
    return compareSpec(spec, spec2);
}
 
Example #2
Source File: TestOAEPParameterSpec.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private static boolean runTest(String mdName, MGF1ParameterSpec mgfSpec,
    byte[] p) throws Exception {
    OAEPParameterSpec spec = new OAEPParameterSpec(mdName, "MGF1",
        mgfSpec, new PSource.PSpecified(p));
    cp = Security.getProvider("SunJCE");
    System.out.println("Testing provider " + cp.getName() + "...");
    AlgorithmParameters ap = AlgorithmParameters.getInstance("OAEP", cp);

    ap.init(spec);
    byte[] encoding = ap.getEncoded();

    AlgorithmParameters ap2 = AlgorithmParameters.getInstance("OAEP", cp);
    ap2.init(encoding);

    OAEPParameterSpec spec2 = (OAEPParameterSpec) ap2.getParameterSpec
            (OAEPParameterSpec.class);
    return compareSpec(spec, spec2);
}
 
Example #3
Source File: TestOAEPParameterSpec.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private static boolean runTest(String mdName, MGF1ParameterSpec mgfSpec,
    byte[] p) throws Exception {
    OAEPParameterSpec spec = new OAEPParameterSpec(mdName, "MGF1",
        mgfSpec, new PSource.PSpecified(p));
    cp = Security.getProvider("SunJCE");
    System.out.println("Testing provider " + cp.getName() + "...");
    AlgorithmParameters ap = AlgorithmParameters.getInstance("OAEP", cp);

    ap.init(spec);
    byte[] encoding = ap.getEncoded();

    AlgorithmParameters ap2 = AlgorithmParameters.getInstance("OAEP", cp);
    ap2.init(encoding);

    OAEPParameterSpec spec2 = (OAEPParameterSpec) ap2.getParameterSpec
            (OAEPParameterSpec.class);
    return compareSpec(spec, spec2);
}
 
Example #4
Source File: PFSecurityUtils.java    From PFLockScreen-Android with Apache License 2.0 6 votes vote down vote up
private void initEncodeCipher(Cipher cipher, String alias, KeyStore keyStore)
        throws PFSecurityException {
    try {
        final PublicKey key = keyStore.getCertificate(alias).getPublicKey();
        final PublicKey unrestricted = KeyFactory.getInstance(key.getAlgorithm()).generatePublic(
                new X509EncodedKeySpec(key.getEncoded()));
        final OAEPParameterSpec spec = new OAEPParameterSpec("SHA-256", "MGF1",
                MGF1ParameterSpec.SHA1, PSource.PSpecified.DEFAULT);
        cipher.init(Cipher.ENCRYPT_MODE, unrestricted, spec);
    } catch (KeyStoreException | InvalidKeySpecException |
            NoSuchAlgorithmException | InvalidKeyException |
            InvalidAlgorithmParameterException e) {
        throw new PFSecurityException(
                "Can not initialize Encode Cipher:" + e.getMessage(),
                PFSecurityUtilsErrorCodes.ERROR_INIT_ENDECODE_CIPHER
        );
    }
}
 
Example #5
Source File: TestOAEPParameterSpec.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static boolean runTest(String mdName, MGF1ParameterSpec mgfSpec,
    byte[] p) throws Exception {
    OAEPParameterSpec spec = new OAEPParameterSpec(mdName, "MGF1",
        mgfSpec, new PSource.PSpecified(p));
    cp = Security.getProvider("SunJCE");
    System.out.println("Testing provider " + cp.getName() + "...");
    AlgorithmParameters ap = AlgorithmParameters.getInstance("OAEP", cp);

    ap.init(spec);
    byte[] encoding = ap.getEncoded();

    AlgorithmParameters ap2 = AlgorithmParameters.getInstance("OAEP", cp);
    ap2.init(encoding);

    OAEPParameterSpec spec2 = (OAEPParameterSpec) ap2.getParameterSpec
            (OAEPParameterSpec.class);
    return compareSpec(spec, spec2);
}
 
Example #6
Source File: TestOAEPParameterSpec.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private static boolean runTest(String mdName, MGF1ParameterSpec mgfSpec,
    byte[] p) throws Exception {
    OAEPParameterSpec spec = new OAEPParameterSpec(mdName, "MGF1",
        mgfSpec, new PSource.PSpecified(p));
    cp = Security.getProvider("SunJCE");
    System.out.println("Testing provider " + cp.getName() + "...");
    AlgorithmParameters ap = AlgorithmParameters.getInstance("OAEP", cp);

    ap.init(spec);
    byte[] encoding = ap.getEncoded();

    AlgorithmParameters ap2 = AlgorithmParameters.getInstance("OAEP", cp);
    ap2.init(encoding);

    OAEPParameterSpec spec2 = (OAEPParameterSpec) ap2.getParameterSpec
            (OAEPParameterSpec.class);
    return compareSpec(spec, spec2);
}
 
Example #7
Source File: TestOAEPParameterSpec.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private static boolean runTest(String mdName, MGF1ParameterSpec mgfSpec,
    byte[] p) throws Exception {
    OAEPParameterSpec spec = new OAEPParameterSpec(mdName, "MGF1",
        mgfSpec, new PSource.PSpecified(p));
    cp = Security.getProvider("SunJCE");
    System.out.println("Testing provider " + cp.getName() + "...");
    AlgorithmParameters ap = AlgorithmParameters.getInstance("OAEP", cp);

    ap.init(spec);
    byte[] encoding = ap.getEncoded();

    AlgorithmParameters ap2 = AlgorithmParameters.getInstance("OAEP", cp);
    ap2.init(encoding);

    OAEPParameterSpec spec2 = (OAEPParameterSpec) ap2.getParameterSpec
            (OAEPParameterSpec.class);
    return compareSpec(spec, spec2);
}
 
Example #8
Source File: TestOAEPParameterSpec.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private static boolean runTest(String mdName, MGF1ParameterSpec mgfSpec,
    byte[] p) throws Exception {
    OAEPParameterSpec spec = new OAEPParameterSpec(mdName, "MGF1",
        mgfSpec, new PSource.PSpecified(p));
    cp = Security.getProvider("SunJCE");
    System.out.println("Testing provider " + cp.getName() + "...");
    AlgorithmParameters ap = AlgorithmParameters.getInstance("OAEP", cp);

    ap.init(spec);
    byte[] encoding = ap.getEncoded();

    AlgorithmParameters ap2 = AlgorithmParameters.getInstance("OAEP", cp);
    ap2.init(encoding);

    OAEPParameterSpec spec2 = (OAEPParameterSpec) ap2.getParameterSpec
            (OAEPParameterSpec.class);
    return compareSpec(spec, spec2);
}
 
Example #9
Source File: TestOAEPParameterSpec.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private static boolean runTest(String mdName, MGF1ParameterSpec mgfSpec,
    byte[] p) throws Exception {
    OAEPParameterSpec spec = new OAEPParameterSpec(mdName, "MGF1",
        mgfSpec, new PSource.PSpecified(p));
    cp = Security.getProvider("SunJCE");
    System.out.println("Testing provider " + cp.getName() + "...");
    AlgorithmParameters ap = AlgorithmParameters.getInstance("OAEP", cp);

    ap.init(spec);
    byte[] encoding = ap.getEncoded();

    AlgorithmParameters ap2 = AlgorithmParameters.getInstance("OAEP", cp);
    ap2.init(encoding);

    OAEPParameterSpec spec2 = (OAEPParameterSpec) ap2.getParameterSpec
            (OAEPParameterSpec.class);
    return compareSpec(spec, spec2);
}
 
Example #10
Source File: TestOAEPParameterSpec.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private static boolean runTest(String mdName, MGF1ParameterSpec mgfSpec,
    byte[] p) throws Exception {
    OAEPParameterSpec spec = new OAEPParameterSpec(mdName, "MGF1",
        mgfSpec, new PSource.PSpecified(p));
    cp = Security.getProvider("SunJCE");
    System.out.println("Testing provider " + cp.getName() + "...");
    AlgorithmParameters ap = AlgorithmParameters.getInstance("OAEP", cp);

    ap.init(spec);
    byte[] encoding = ap.getEncoded();

    AlgorithmParameters ap2 = AlgorithmParameters.getInstance("OAEP", cp);
    ap2.init(encoding);

    OAEPParameterSpec spec2 = (OAEPParameterSpec) ap2.getParameterSpec
            (OAEPParameterSpec.class);
    return compareSpec(spec, spec2);
}
 
Example #11
Source File: AlgorithmParametersSpi.java    From RipplePower with Apache License 2.0 6 votes vote down vote up
/**
 * Return the PKCS#1 ASN.1 structure RSAES-OAEP-params.
 */
protected byte[] engineGetEncoded() 
{
    AlgorithmIdentifier hashAlgorithm = new AlgorithmIdentifier(
                                                    DigestFactory.getOID(currentSpec.getDigestAlgorithm()),
                                                    DERNull.INSTANCE);
    MGF1ParameterSpec mgfSpec = (MGF1ParameterSpec)currentSpec.getMGFParameters();
    AlgorithmIdentifier maskGenAlgorithm = new AlgorithmIdentifier(
                                                    PKCSObjectIdentifiers.id_mgf1,
                                                    new AlgorithmIdentifier(DigestFactory.getOID(mgfSpec.getDigestAlgorithm()), DERNull.INSTANCE));
    PSource.PSpecified      pSource = (PSource.PSpecified)currentSpec.getPSource();
    AlgorithmIdentifier pSourceAlgorithm = new AlgorithmIdentifier(
                                                    PKCSObjectIdentifiers.id_pSpecified, new DEROctetString(pSource.getValue()));
    RSAESOAEPparams oaepP = new RSAESOAEPparams(hashAlgorithm, maskGenAlgorithm, pSourceAlgorithm);
    
    try
    {
        return oaepP.getEncoded(ASN1Encoding.DER);
    }
    catch (IOException e)
    {
        throw new RuntimeException("Error encoding OAEPParameters");
    }
}
 
Example #12
Source File: TestOAEPParameterSpec.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
private static boolean runTest(String mdName, MGF1ParameterSpec mgfSpec,
    byte[] p) throws Exception {
    OAEPParameterSpec spec = new OAEPParameterSpec(mdName, "MGF1",
        mgfSpec, new PSource.PSpecified(p));
    cp = Security.getProvider("SunJCE");
    System.out.println("Testing provider " + cp.getName() + "...");
    AlgorithmParameters ap = AlgorithmParameters.getInstance("OAEP", cp);

    ap.init(spec);
    byte[] encoding = ap.getEncoded();

    AlgorithmParameters ap2 = AlgorithmParameters.getInstance("OAEP", cp);
    ap2.init(encoding);

    OAEPParameterSpec spec2 = (OAEPParameterSpec) ap2.getParameterSpec
            (OAEPParameterSpec.class);
    return compareSpec(spec, spec2);
}
 
Example #13
Source File: TestOAEPParameterSpec.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static boolean runTest(String mdName, MGF1ParameterSpec mgfSpec,
    byte[] p) throws Exception {
    OAEPParameterSpec spec = new OAEPParameterSpec(mdName, "MGF1",
        mgfSpec, new PSource.PSpecified(p));
    cp = Security.getProvider("SunJCE");
    System.out.println("Testing provider " + cp.getName() + "...");
    AlgorithmParameters ap = AlgorithmParameters.getInstance("OAEP", cp);

    ap.init(spec);
    byte[] encoding = ap.getEncoded();

    AlgorithmParameters ap2 = AlgorithmParameters.getInstance("OAEP", cp);
    ap2.init(encoding);

    OAEPParameterSpec spec2 = (OAEPParameterSpec) ap2.getParameterSpec
            (OAEPParameterSpec.class);
    return compareSpec(spec, spec2);
}
 
Example #14
Source File: AlgorithmParametersSpi.java    From ripple-lib-java with ISC License 6 votes vote down vote up
/**
 * Return the PKCS#1 ASN.1 structure RSAES-OAEP-params.
 */
protected byte[] engineGetEncoded() 
{
    AlgorithmIdentifier hashAlgorithm = new AlgorithmIdentifier(
                                                    DigestFactory.getOID(currentSpec.getDigestAlgorithm()),
                                                    DERNull.INSTANCE);
    MGF1ParameterSpec mgfSpec = (MGF1ParameterSpec)currentSpec.getMGFParameters();
    AlgorithmIdentifier maskGenAlgorithm = new AlgorithmIdentifier(
                                                    PKCSObjectIdentifiers.id_mgf1,
                                                    new AlgorithmIdentifier(DigestFactory.getOID(mgfSpec.getDigestAlgorithm()), DERNull.INSTANCE));
    PSource.PSpecified      pSource = (PSource.PSpecified)currentSpec.getPSource();
    AlgorithmIdentifier pSourceAlgorithm = new AlgorithmIdentifier(
                                                    PKCSObjectIdentifiers.id_pSpecified, new DEROctetString(pSource.getValue()));
    RSAESOAEPparams oaepP = new RSAESOAEPparams(hashAlgorithm, maskGenAlgorithm, pSourceAlgorithm);
    
    try
    {
        return oaepP.getEncoded(ASN1Encoding.DER);
    }
    catch (IOException e)
    {
        throw new RuntimeException("Error encoding OAEPParameters");
    }
}
 
Example #15
Source File: TestOAEPParameterSpec.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static boolean runTest(String mdName, MGF1ParameterSpec mgfSpec,
    byte[] p) throws Exception {
    OAEPParameterSpec spec = new OAEPParameterSpec(mdName, "MGF1",
        mgfSpec, new PSource.PSpecified(p));
    cp = Security.getProvider("SunJCE");
    System.out.println("Testing provider " + cp.getName() + "...");
    AlgorithmParameters ap = AlgorithmParameters.getInstance("OAEP", cp);

    ap.init(spec);
    byte[] encoding = ap.getEncoded();

    AlgorithmParameters ap2 = AlgorithmParameters.getInstance("OAEP", cp);
    ap2.init(encoding);

    OAEPParameterSpec spec2 = (OAEPParameterSpec) ap2.getParameterSpec
            (OAEPParameterSpec.class);
    return compareSpec(spec, spec2);
}
 
Example #16
Source File: OAEPParameters.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
protected <T extends AlgorithmParameterSpec>
    T engineGetParameterSpec(Class<T> paramSpec)
    throws InvalidParameterSpecException {
    if (OAEPParameterSpec.class.isAssignableFrom(paramSpec)) {
        return paramSpec.cast(
            new OAEPParameterSpec(mdName, "MGF1", mgfSpec,
                                  new PSource.PSpecified(p)));
    } else {
        throw new InvalidParameterSpecException
            ("Inappropriate parameter specification");
    }
}
 
Example #17
Source File: OAEPParameters.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
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");
    }
}
 
Example #18
Source File: CipherSpi.java    From RipplePower with Apache License 2.0 5 votes vote down vote up
private void initFromSpec(
    OAEPParameterSpec pSpec)
    throws NoSuchPaddingException
{
    MGF1ParameterSpec mgfParams = (MGF1ParameterSpec)pSpec.getMGFParameters();
    Digest digest = DigestFactory.getDigest(mgfParams.getDigestAlgorithm());
    
    if (digest == null)
    {
        throw new NoSuchPaddingException("no match on OAEP constructor for digest algorithm: "+ mgfParams.getDigestAlgorithm());
    }

    cipher = new OAEPEncoding(new RSABlindedEngine(), digest, ((PSource.PSpecified)pSpec.getPSource()).getValue());
    paramSpec = pSpec;
}
 
Example #19
Source File: OAEPParameters.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
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");
    }
}
 
Example #20
Source File: AndroidOaepKeystoreSecretKeyWrapper.java    From Android-Vault with Apache License 2.0 5 votes vote down vote up
@Override
public AlgorithmParameterSpec buildCipherAlgorithmParameterSpec() {
    return new OAEPParameterSpec(
            MESSAGE_DIGEST_ALGORITHM_NAME,
            MASK_GENERATION_FUNCTION_ALGORITHM_NAME,
            MGF1ParameterSpec.SHA1,
            PSource.PSpecified.DEFAULT);
}
 
Example #21
Source File: RsaOaepTest.java    From wycheproof with Apache License 2.0 5 votes vote down vote up
protected static OAEPParameterSpec getOaepParameters(JsonObject group,
                                                     JsonObject test) throws Exception {
  String sha = getString(group, "sha");
  String mgf = getString(group, "mgf");
  String mgfSha = getString(group, "mgfSha");
  PSource p = PSource.PSpecified.DEFAULT;
  if (test.has("label")) {
    p = new PSource.PSpecified(getBytes(test, "label"));
  }
  return new OAEPParameterSpec(sha, mgf, new MGF1ParameterSpec(mgfSha), p); 
}
 
Example #22
Source File: OAEPParameters.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
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");
    }
}
 
Example #23
Source File: PSourceTest.java    From j2objc with Apache License 2.0 5 votes vote down vote up
/**
 * getValue() method testing. Tests that returned array is equal to the
 * array specified in the constructor. Checks that modification
 * of returned array does not affect the internal array.
 */
public void testGetValue() {
    byte[] p = new byte[] {1, 2, 3, 4, 5};

    PSource.PSpecified ps = new PSource.PSpecified(p);
    byte[] result = ps.getValue();
    if (!Arrays.equals(p, result)) {
        fail("The returned array does not equal to the specified "
                + "in the constructor.");
    }
    result[0]++;
    assertFalse("The change of returned by getValue() array "
            + "should not cause the change of internal array.",
            result[0] == ps.getValue()[0]);
}
 
Example #24
Source File: OAEPParameters.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
protected <T extends AlgorithmParameterSpec>
    T engineGetParameterSpec(Class<T> paramSpec)
    throws InvalidParameterSpecException {
    if (OAEPParameterSpec.class.isAssignableFrom(paramSpec)) {
        return paramSpec.cast(
            new OAEPParameterSpec(mdName, "MGF1", mgfSpec,
                                  new PSource.PSpecified(p)));
    } else {
        throw new InvalidParameterSpecException
            ("Inappropriate parameter specification");
    }
}
 
Example #25
Source File: OAEPParameters.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
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");
    }
}
 
Example #26
Source File: TestOAEPParameterSpec.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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;
    }
}
 
Example #27
Source File: OAEPParameters.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
protected <T extends AlgorithmParameterSpec>
    T engineGetParameterSpec(Class<T> paramSpec)
    throws InvalidParameterSpecException {
    if (OAEPParameterSpec.class.isAssignableFrom(paramSpec)) {
        return paramSpec.cast(
            new OAEPParameterSpec(mdName, "MGF1", mgfSpec,
                                  new PSource.PSpecified(p)));
    } else {
        throw new InvalidParameterSpecException
            ("Inappropriate parameter specification");
    }
}
 
Example #28
Source File: OAEPParameters.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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");
    }
}
 
Example #29
Source File: TestOAEPParameterSpec.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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;
    }
}
 
Example #30
Source File: OAEPParameters.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
protected <T extends AlgorithmParameterSpec>
    T engineGetParameterSpec(Class<T> paramSpec)
    throws InvalidParameterSpecException {
    if (OAEPParameterSpec.class.isAssignableFrom(paramSpec)) {
        return paramSpec.cast(
            new OAEPParameterSpec(mdName, "MGF1", mgfSpec,
                                  new PSource.PSpecified(p)));
    } else {
        throw new InvalidParameterSpecException
            ("Inappropriate parameter specification");
    }
}