Java 8 OAEPParameterSpec - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 OAEPParameterSpec class.

This code example shows how to use the following methods:getDigestAlgorithm, getMGFAlgorithm, getMGFParameters, getPSource
 
    private static Provider cp;
 
    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);

7
CodeRank
This code example shows how to use the following methods:getDigestAlgorithm, getMGFAlgorithm, getMGFParameters, getPSource
 
    private static Provider cp;
 
    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);

6
CodeRank
This code example shows how to use the following methods:getDigestAlgorithm, getMGFAlgorithm, getMGFParameters, getPSource
OAEPParameterSpec spec = (OAEPParameterSpec)params;
                 
                paramSpec = params;
                 
                if (!spec.getMGFAlgorithm().equalsIgnoreCase("MGF1") && !spec.getMGFAlgorithm().equals(PKCSObjectIdentifiers.id_mgf1.getId()))
                { 
                    throw new InvalidAlgorithmParameterException("unknown mask generation function specified");
                } 
                 
                if (!(spec.getMGFParameters() instanceof MGF1ParameterSpec))
                { 
                    throw new InvalidAlgorithmParameterException("unkown MGF parameters");
                } 
     
                Digest digest = DigestFactory.getDigest(spec.getDigestAlgorithm());
 
                if (digest == null)
                { 
                    throw new InvalidAlgorithmParameterException("no match on digest algorithm: "+ spec.getDigestAlgorithm());

6
CodeRank
This code example shows how to use the following methods:
import tests.security.AlgorithmParametersTest; 
 
public class AlgorithmParametersTestOAEP extends AlgorithmParametersTest { 
 
    public AlgorithmParametersTestOAEP() { 
        super("OAEP", new AlgorithmParameterAsymmetricHelper("RSA"), new OAEPParameterSpec("SHA-1", "MGF1", MGF1ParameterSpec.SHA1, PSource.PSpecified.DEFAULT)); 
    } 
 
} 
6
CodeRank
This code example shows how to use the following methods:getDigestAlgorithm, getMGFAlgorithm, getMGFParameters, getPSource
OAEPParameterSpec   spec = (OAEPParameterSpec)params;
                 
                paramSpec = params;
                 
                if (!spec.getMGFAlgorithm().equalsIgnoreCase("MGF1") && !spec.getMGFAlgorithm().equals(PKCSObjectIdentifiers.id_mgf1.getId()))
                { 
                    throw new InvalidAlgorithmParameterException("unknown mask generation function specified");
                } 
                 
                if (!(spec.getMGFParameters() instanceof MGF1ParameterSpec))
                { 
                    throw new InvalidAlgorithmParameterException("unkown MGF parameters");
                } 
     
                Digest digest = JCEDigestUtil.getDigest(spec.getDigestAlgorithm());
 
                if (digest == null)
                { 
                    throw new InvalidAlgorithmParameterException("no match on digest algorithm: "+ spec.getDigestAlgorithm());

6
CodeRank
This code example shows how to use the following methods:getDigestAlgorithm, getMGFAlgorithm, getMGFParameters, getPSource
 
    private static Provider cp;
 
    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);

6
CodeRank
This code example shows how to use the following methods:
import tests.security.AlgorithmParametersTest; 
 
public class AlgorithmParametersTestOAEP extends AlgorithmParametersTest { 
 
    public AlgorithmParametersTestOAEP() { 
        super("OAEP", new AlgorithmParameterAsymmetricHelper("RSA"), new OAEPParameterSpec("SHA-1", "MGF1", MGF1ParameterSpec.SHA1, PSource.PSpecified.DEFAULT)); 
    } 
 
} 
5
CodeRank
This code example shows how to use the following methods:
 
@TestTargetClass(targets.AlgorithmParameters.OAEP.class) 
public class AlgorithmParametersTestOAEP extends AlgorithmParametersTest { 
 
    public AlgorithmParametersTestOAEP() { 
        super("OAEP", new AlgorithmParameterAsymmetricHelper("RSA"), new OAEPParameterSpec("SHA-1", "MGF1", MGF1ParameterSpec.SHA1, PSource.PSpecified.DEFAULT)); 
    } 
 
} 
5
CodeRank
This code example shows how to use the following methods:
        byte[] pSrc2 = { (byte) 0x01, (byte) 0x01, (byte) 0x01, (byte) 0x01,
                         (byte) 0x02, (byte) 0x02, (byte) 0x03, (byte) 0x04 
        }; 
        OAEPParameterSpec spec1 = new OAEPParameterSpec(hashAlg,
            "MGF1", MGF1ParameterSpec.SHA1, new PSource.PSpecified(pSrc1));
        OAEPParameterSpec spec2 = new OAEPParameterSpec(hashAlg,
            "MGF1", MGF1ParameterSpec.SHA1, new PSource.PSpecified(pSrc2));
        byte[] plainText = new byte[dataLength];
        byte[] cipherText, recovered;
        // do encryption with parameters#1 
        System.out.println("Testing with user-supplied parameters...");
        c.init(Cipher.ENCRYPT_MODE, publicKey, spec1);
        cipherText = c.doFinal(plainText);
 
        // test#1: decrypt with parameters#1 
        c.init(Cipher.DECRYPT_MODE, privateKey, spec1);
        recovered = c.doFinal(cipherText);
        if (Arrays.equals(plainText, recovered) == false) {
            throw new Exception("Decrypted data does not match");
        } 
5
CodeRank
This code example shows how to use the following methods:
 
@TestTargetClass(targets.AlgorithmParameters.OAEP.class) 
public class AlgorithmParametersTestOAEP extends AlgorithmParametersTest { 
 
    public AlgorithmParametersTestOAEP() { 
        super("OAEP", new AlgorithmParameterAsymmetricHelper("RSA"), new OAEPParameterSpec("SHA-1", "MGF1", MGF1ParameterSpec.SHA1, PSource.PSpecified.DEFAULT)); 
    } 
 
} 
5
CodeRank
See Code Examples for Java 8 OAEPParameterSpec Methods: