Java 8 PSSParameterSpec - 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 PSSParameterSpec class.

This code example shows how to use the following methods:getDigestAlgorithm, getMGFParameters, getSaltLength, getTrailerField
        protected byte[] engineGetEncoded()  
            throws IOException 
        { 
            PSSParameterSpec pssSpec = currentSpec;
            AlgorithmIdentifier hashAlgorithm = new AlgorithmIdentifier(
                                                DigestFactory.getOID(pssSpec.getDigestAlgorithm()),
                                                DERNull.INSTANCE); 
            MGF1ParameterSpec mgfSpec = (MGF1ParameterSpec)pssSpec.getMGFParameters();
            AlgorithmIdentifier maskGenAlgorithm = new AlgorithmIdentifier(
                                                PKCSObjectIdentifiers.id_mgf1, 
                                                new AlgorithmIdentifier(DigestFactory.getOID(mgfSpec.getDigestAlgorithm()), DERNull.INSTANCE));
            RSASSAPSSparams pssP = new RSASSAPSSparams(hashAlgorithm, maskGenAlgorithm, new ASN1Integer(pssSpec.getSaltLength()), new ASN1Integer(pssSpec.getTrailerField()));
             
            return pssP.getEncoded("DER");
        } 
     
        protected byte[] engineGetEncoded( 
            String format)
            throws IOException 
        { 
7
CodeRank
This code example shows how to use the following methods:getDigestAlgorithm, getMGFParameters, getSaltLength, getTrailerField
        protected byte[] engineGetEncoded()  
            throws IOException 
        { 
            PSSParameterSpec pssSpec = currentSpec;
            AlgorithmIdentifier hashAlgorithm = new AlgorithmIdentifier(
                                                DigestFactory.getOID(pssSpec.getDigestAlgorithm()),
                                                // BEGIN android-changed 
                                                DERNull.INSTANCE); 
                                                // END android-changed 
            MGF1ParameterSpec mgfSpec = (MGF1ParameterSpec)pssSpec.getMGFParameters();
            AlgorithmIdentifier maskGenAlgorithm = new AlgorithmIdentifier(
                                                PKCSObjectIdentifiers.id_mgf1, 
                                                // BEGIN android-changed 
                                                new AlgorithmIdentifier(DigestFactory.getOID(mgfSpec.getDigestAlgorithm()), DERNull.INSTANCE));
                                                // END android-changed 
            RSASSAPSSparams pssP = new RSASSAPSSparams(hashAlgorithm, maskGenAlgorithm, new ASN1Integer(pssSpec.getSaltLength()), new ASN1Integer(pssSpec.getTrailerField()));
             
            return pssP.getEncoded("DER");
        } 
     
        protected byte[] engineGetEncoded( 
5
CodeRank
This code example shows how to use the following methods:getDigestAlgorithm
    /** 
     * Test for <code>getDigestAlgorithm()</code> method 
     * Assertion: returns message digest algorithm name  
     */ 
    public final void testGetDigestAlgorithm() { 
        PSSParameterSpec pssps = new PSSParameterSpec("SHA-1", "MGF1",
                MGF1ParameterSpec.SHA1, 20, 1);
        assertEquals("SHA-1", pssps.getDigestAlgorithm());
    } 
 
    /** 
     * Test for <code>getMGFAlgorithm()</code> method 
     * Assertion: returns mask generation function algorithm name  
     */ 
    public final void testGetMGFAlgorithm() { 
        PSSParameterSpec pssps = new PSSParameterSpec("SHA-1", "MGF1",
                MGF1ParameterSpec.SHA1, 20, 1);
        assertEquals("MGF1", pssps.getMGFAlgorithm());
    } 
 
5
CodeRank
This code example shows how to use the following methods:getSaltLength
        Signature normalSig = Signature.getInstance(sigName, "BC");
 
        PSSParameterSpec spec = (PSSParameterSpec)normalSig.getParameters().getParameterSpec(PSSParameterSpec.class);
 
        // Make sure we generate the same 'random' salt for both normal and raw signers 
        int saltLen = spec.getSaltLength();
        byte[] fixedRandomBytes = new byte[saltLen];
        random.nextBytes(fixedRandomBytes);
 
        normalSig.initSign(privKey, new FixedSecureRandom(fixedRandomBytes));
        normalSig.update(sampleMessage);
        byte[] normalResult = normalSig.sign();
 
        MessageDigest digest = MessageDigest.getInstance(digestOID.getId(), "BC");
        byte[] hash = digest.digest(sampleMessage);
 
        Signature rawSig = Signature.getInstance("RAWRSASSA-PSS", "BC");
 
        // Need to init the params explicitly to avoid having a 'raw' variety of every PSS algorithm 
        rawSig.setParameter(spec);
5
CodeRank
This code example shows how to use the following methods:getTrailerField
    /** 
     * Test for <code>getTrailerField()</code> method<br> 
     * Assertion: returns trailer field value 
     */ 
    public final void testGetTrailerField() { 
        PSSParameterSpec pssps = new PSSParameterSpec("SHA-1", "MGF1",
                MGF1ParameterSpec.SHA1, 20, 1);
        assertEquals(1, pssps.getTrailerField());
    } 
 
    /** 
     * Test for <code>DEFAULT</code> field<br> 
     * Assertion: default message digest algorithm name is "SHA-1" 
     */ 
    public final void testDEFAULTmdName() { 
        assertEquals("SHA-1", PSSParameterSpec.DEFAULT.getDigestAlgorithm());
    } 
 
    /** 
     * Test for <code>DEFAULT</code> field<br> 
5
CodeRank
This code example shows how to use the following methods:
    static public class SHA224withRSA 
        extends JDKPSSSigner 
    { 
        public SHA224withRSA() 
        { 
            super("SHA2224withRSAandMGF1", new RSAEngine(), new PSSParameterSpec("SHA-224", "MGF1", new MGF1ParameterSpec("SHA-224"), 28, 1));
        } 
    } 
     
    static public class SHA256withRSA 
        extends JDKPSSSigner 
    { 
        public SHA256withRSA() 
        { 
            super("SHA256withRSAandMGF1", new RSAEngine(), new PSSParameterSpec("SHA-256", "MGF1", new MGF1ParameterSpec("SHA-256"), 32, 1));
        } 
    } 
 
    static public class SHA384withRSA 
        extends JDKPSSSigner 
5
CodeRank
This code example shows how to use the following methods:getMGFAlgorithm
    /** 
     * Test for <code>getMGFAlgorithm()</code> method 
     * Assertion: returns mask generation function algorithm name  
     */ 
    public final void testGetMGFAlgorithm() { 
        PSSParameterSpec pssps = new PSSParameterSpec("SHA-1", "MGF1",
                MGF1ParameterSpec.SHA1, 20, 1);
        assertEquals("MGF1", pssps.getMGFAlgorithm());
    } 
 
    /** 
     * Test #1 for <code>getMGFParameters()</code> method 
     * Assertion: returns mask generation function parameters  
     */ 
    public final void testGetMGFParameters01() { 
        PSSParameterSpec pssps = new PSSParameterSpec("SHA-1", "MGF1",
                MGF1ParameterSpec.SHA1, 20, 1);
        assertTrue(MGF1ParameterSpec.SHA1.equals(pssps.getMGFParameters()));
    } 
     
5
CodeRank
This code example shows how to use the following methods:
                currentSpec = new PSSParameterSpec(
                                       pssP.getHashAlgorithm().getAlgorithm().getId(), 
                                       pssP.getMaskGenAlgorithm().getAlgorithm().getId(), 
                                       new MGF1ParameterSpec(AlgorithmIdentifier.getInstance(pssP.getMaskGenAlgorithm().getParameters()).getAlgorithm().getId()),
                                       pssP.getSaltLength().intValue(),
                                       pssP.getTrailerField().intValue());
            } 
            catch (ClassCastException e)
            { 
                throw new IOException("Not a valid PSS Parameter encoding.");
            } 
            catch (ArrayIndexOutOfBoundsException e)
            { 
                throw new IOException("Not a valid PSS Parameter encoding.");
            } 
        } 
     
        protected void engineInit( 
            byte[] params,
            String format)
4
CodeRank
This code example shows how to use the following methods:
            try 
            { 
                RSASSAPSSparams pssP = RSASSAPSSparams.getInstance(params);
 
                currentSpec = new PSSParameterSpec(
                                       pssP.getSaltLength().intValue());
            } 
            catch (ClassCastException e)
            { 
                throw new IOException("Not a valid PSS Parameter encoding.");
            } 
            catch (ArrayIndexOutOfBoundsException e)
            { 
                throw new IOException("Not a valid PSS Parameter encoding.");
            } 
        } 
     
        protected void engineInit( 
            byte[] params,
            String format)
4
CodeRank
This code example shows how to use the following methods:getSaltLength
        Signature normalSig = Signature.getInstance(sigName, "BC");
 
        PSSParameterSpec spec = (PSSParameterSpec)normalSig.getParameters().getParameterSpec(PSSParameterSpec.class);
 
        // Make sure we generate the same 'random' salt for both normal and raw signers 
        int saltLen = spec.getSaltLength();
        byte[] fixedRandomBytes = new byte[saltLen];
        random.nextBytes(fixedRandomBytes);
 
        normalSig.initSign(privKey, new FixedSecureRandom(fixedRandomBytes));
        normalSig.update(sampleMessage);
        byte[] normalResult = normalSig.sign();
 
        MessageDigest digest = MessageDigest.getInstance(digestOID.getId(), "BC");
        byte[] hash = digest.digest(sampleMessage);
 
        Signature rawSig = Signature.getInstance("RAWRSASSA-PSS", "BC");
 
        // Need to init the params explicitly to avoid having a 'raw' variety of every PSS algorithm 
        rawSig.setParameter(spec);
4
CodeRank
See Code Examples for Java 8 PSSParameterSpec Methods: