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

This code example shows how to use the following methods:getAlgorithm, getProvider, setParameter
        DEREncodable params) 
        throws NoSuchAlgorithmException, SignatureException, InvalidKeyException 
    { 
        if (params != null && !derNull.equals(params))
        { 
            AlgorithmParameters  sigParams = AlgorithmParameters.getInstance(signature.getAlgorithm(), signature.getProvider());
             
            try 
            { 
                sigParams.init(params.getDERObject().getDEREncoded());
            } 
            catch (IOException e)
            { 
                throw new SignatureException("IOException decoding parameters: " + e.getMessage());
            } 
             
            if (signature.getAlgorithm().endsWith("MGF1"))
            { 
                try 
                { 

8
CodeRank
This code example shows how to use the following methods:getAlgorithm, getProvider, setParameter
        DEREncodable params) 
        throws NoSuchAlgorithmException, SignatureException, InvalidKeyException 
    { 
        if (params != null && !derNull.equals(params))
        { 
            AlgorithmParameters  sigParams = AlgorithmParameters.getInstance(signature.getAlgorithm(), signature.getProvider());
             
            try 
            { 
                sigParams.init(params.getDERObject().getDEREncoded());
            } 
            catch (IOException e)
            { 
                throw new SignatureException("IOException decoding parameters: " + e.getMessage());
            } 
             
            if (signature.getAlgorithm().endsWith("MGF1"))
            { 
                try 
                { 

8
CodeRank
This code example shows how to use the following methods:initSign, initVerify, sign, update, verify
KeyFactory          f = KeyFactory.getInstance("ECDSA", "BC");
        PrivateKey          sKey = f.generatePrivate(priKey);
        PublicKey           vKey = f.generatePublic(pubKey);
 
        sgr.initSign(sKey, k);
 
        sgr.update(message);
 
        byte[]  sigBytes = sgr.sign();
 
        sgr.initVerify(vKey);
 
        sgr.update(message);
 
        if (!sgr.verify(sigBytes))
        { 
            fail(size + " bit EC verification failed");
        } 
 
        BigInteger[]  sig = derDecode(sigBytes);
7
CodeRank
This code example shows how to use the following methods:initSign, sign, update
		KeyPair keyPair = keyPairGen.generateKeyPair();
//		PublicKey publicKey = (RSAPublicKey) keyPair.getPublic(); 
		PrivateKey privateKey = keyPair.getPrivate();
		signature = Signature.getInstance("SHA1withECDSA");
 
		signature.initSign(privateKey);
		 
		signature.update(plainBytes);
		signedBytes = signature.sign();
	} 
	//  
 
	public void execute() throws Exception { 
		signature.update(plainBytes);
		signedBytes = signature.sign();
	} 
} 
7
CodeRank
This code example shows how to use the following methods:initSign, sign, update
    } 
 
    private void doTestHMACDetECDSA(Signature detSigner, byte[] data, PrivateKey privKey, BigInteger r, BigInteger s)
        throws Exception 
    { 
        detSigner.initSign(privKey);
 
        detSigner.update(data, 0, data.length);
 
        byte[] m = detSigner.sign();
 
        ASN1Sequence seq = ASN1Sequence.getInstance(m);
 
 
        if (!r.equals(ASN1Integer.getInstance(seq.getObjectAt(0)).getValue()))
        { 
            fail("r value wrong"); 
        } 
        if (!s.equals(ASN1Integer.getInstance(seq.getObjectAt(1)).getValue()))
        { 
7
CodeRank
This code example shows how to use the following methods:getAlgorithm, initSign, initVerify, sign, update
            } 
        } 
    } 
 
    private void test_Signature(Signature sig, KeyPair keyPair) throws Exception {
        sig.initSign(keyPair.getPrivate());
        sig.update(DATA);
        byte[] signature = sig.sign();
        assertNotNull(sig.getAlgorithm(), signature);
        assertTrue(sig.getAlgorithm(), signature.length > 0);
 
        sig.initVerify(keyPair.getPublic());
        sig.update(DATA);
        assertTrue(sig.getAlgorithm(), sig.verify(signature));
 
        // After verify, should be reusable as if we are after initVerify 
        sig.update(DATA);
        assertTrue(sig.getAlgorithm(), sig.verify(signature));
 
        // Calling Signature.verify a second time should not throw 

6
CodeRank
This code example shows how to use the following methods:initSign, sign, update
		KeyPair keyPair = keyPairGen.generateKeyPair();
//		PublicKey publicKey = (RSAPublicKey) keyPair.getPublic(); 
		PrivateKey privateKey = keyPair.getPrivate();
		signature = Signature.getInstance("SHA1withRSA");
 
		signature.initSign(privateKey);
		 
		signature.update(plainBytes);
		signedBytes = signature.sign();
	} 
	//  
 
	public void execute() throws Exception { 
		signature.update(plainBytes);
		signedBytes = signature.sign();
	} 
} 
7
CodeRank
This code example shows how to use the following methods:initSign, initVerify, sign, update, verify
KeyFactory          f = KeyFactory.getInstance("ECDSA", "BC");
        PrivateKey          sKey = f.generatePrivate(priKey);
        PublicKey           vKey = f.generatePublic(pubKey);
 
        sgr.initSign(sKey, k);
 
        sgr.update(message);
 
        byte[]  sigBytes = sgr.sign();
 
        sgr.initVerify(vKey);
 
        sgr.update(message);
 
        if (!sgr.verify(sigBytes))
        { 
            fail(size + " bit EC verification failed");
        } 
 
        BigInteger[]  sig = derDecode(sigBytes);
6
CodeRank
This code example shows how to use the following methods:initSign, sign, update
    } 
 
    private byte[] computeSignature(String stringToBeSigned, PrivateKey signingKey) throws GeneralSecurityException {
        String algo = signingKey.getAlgorithm();
        Signature sig = getSignature(algo);
        sig.initSign(signingKey);
        sig.update(stringToBeSigned.getBytes());
        return sig.sign();
    } 
 
    public void validateSignature(SamlRedirectMessage urlEncodedRedirectMessage, PublicKey publicKey) throws InvalidRequestException {
        if (urlEncodedRedirectMessage.getSignature() == null) {
            throw new InvalidRequestException("Signature parameter is not present."); 
        } 
 
        String urlDecodedSignature;
        try { 
            urlDecodedSignature = URLDecoder.decode(urlEncodedRedirectMessage.getSignature(), "UTF-8");
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
6
CodeRank
This code example shows how to use the following methods:getAlgorithm, getProvider, setParameter
        ASN1Encodable params)
        throws NoSuchAlgorithmException, SignatureException, InvalidKeyException 
    { 
        if (params != null && !derNull.equals(params))
        { 
            AlgorithmParameters  sigParams = AlgorithmParameters.getInstance(signature.getAlgorithm(), signature.getProvider());
             
            try 
            { 
                sigParams.init(params.toASN1Primitive().getEncoded());
            } 
            catch (IOException e)
            { 
                throw new SignatureException("IOException decoding parameters: " + e.getMessage());
            } 
             
            if (signature.getAlgorithm().endsWith("MGF1"))
            { 
                try 
                { 

7
CodeRank
See Code Examples for Java 8 Signature Methods: