List of usage examples for java.security Signature update
public final void update(ByteBuffer data) throws SignatureException
From source file:org.chaston.oakfunds.xsrf.XsrfSigner.java
public String sign(String material) throws GeneralSecurityException { Signature sig = Signature.getInstance("SHA256withRSA"); sig.initSign(privateKey, secureRandom); sig.update(material.getBytes(CHARSET)); return Base64.encodeBase64String(sig.sign()); }
From source file:com.ibm.mobilefirstplatform.clientsdk.android.security.mca.internal.certificate.DefaultJSONSigner.java
private byte[] signCsrData(String csrJSONData, PrivateKey privateKey) throws NoSuchAlgorithmException, InvalidKeyException, SignatureException { Signature signature = Signature.getInstance("SHA256withRSA"); signature.initSign(privateKey);//from w ww . j a v a 2s . c o m signature.update(csrJSONData.getBytes()); return signature.sign(); }
From source file:org.jgrades.lic.api.crypto.decrypt.SignatureValidator.java
public boolean signatureValidated(File encryptedLicenceFile, File signatureFile) throws LicenceCryptographyException { try {//from ww w .j a va 2 s.com X509Certificate certificate = keyExtractor.getCertificateForVerification(); PublicKey publicKey = certificate.getPublicKey(); Signature signature = Signature.getInstance(SIGNATURE_PROVIDER_INTERFACE); signature.initVerify(publicKey); signature.update(FileUtils.readFileToByteArray(encryptedLicenceFile)); return signature.verify(FileUtils.readFileToByteArray(signatureFile)); } catch (SignatureException e) { LOGGER.error("Signature {} validation failed", signatureFile.getAbsolutePath(), e); return false; } catch (NoSuchAlgorithmException | InvalidKeyException | IOException e) { throw new LicenceCryptographyException(e); } }
From source file:netinf.common.security.impl.SignatureAlgorithmImpl.java
/** * @see SignatureAlgorithm#sign(String, PrivateKey, String) *//* www . j ava 2s . co m*/ @Override public String sign(String originalString, PrivateKey sk, String hashAndSignatureFunction) throws NoSuchAlgorithmException, InvalidKeyException, SignatureException { Signature signature = Signature.getInstance(hashAndSignatureFunction); signature.initSign(sk); signature.update(originalString.getBytes()); return Base64.encodeBase64String(signature.sign()); }
From source file:netinf.common.security.impl.SignatureAlgorithmImpl.java
/** * @see SignatureAlgorithm#verifySignature(String, String, PublicKey, String) */// w w w . ja va2 s . com @Override public boolean verifySignature(String originalString, String signatureString, PublicKey pk, String hashAndSignatureFunction) throws SignatureException, NoSuchAlgorithmException, InvalidKeyException { Signature signature = Signature.getInstance(hashAndSignatureFunction); signature.initVerify(pk); signature.update(originalString.getBytes()); return signature.verify(Base64.decodeBase64(signatureString)); }
From source file:ru.codeinside.gws.crypto.cryptopro.Pkcs7Test.java
@Test public void testEncoding() throws Exception { CryptoProvider.loadCertificate();//from w w w .j a va 2 s . c o m byte[] content = IOUtils .toByteArray(R.getRequiredResourceStream("rr/req_cb8cff92-c788-46cf-a97f-f5c6f0170be5.xml")); final Signature signature = Signature.getInstance("GOST3411withGOST3410EL"); signature.initSign(CryptoProvider.privateKey); signature.update(content); byte[] sign = signature.sign(); byte[] pkcs7 = SunPkcs7 .toPkcs7(new ru.codeinside.gws.api.Signature(CryptoProvider.cert, null, sign, false)); ru.codeinside.gws.api.Signature sig2 = SunPkcs7.fromPkcs7(pkcs7); assertEquals(CryptoProvider.cert, sig2.certificate); assertArrayEquals(sign, sig2.sign); assertTrue(R.provider.validate(sig2, null, content)); }
From source file:org.jgrades.security.utils.SignatureProvider.java
public boolean signatureValidated(File encryptedLicenceFile, File signatureFile) { try {/*from w w w . j a va2 s. c om*/ X509Certificate certificate = extractor.getCertificateForVerification(); PublicKey publicKey = certificate.getPublicKey(); Signature signature = Signature.getInstance(SIGNATURE_PROVIDER_INTERFACE); signature.initVerify(publicKey); signature.update(FileUtils.readFileToByteArray(encryptedLicenceFile)); return signature.verify(FileUtils.readFileToByteArray(signatureFile)); } catch (SignatureException e) { LOGGER.debug("Signature verification failed", e); return false; } catch (NoSuchAlgorithmException | InvalidKeyException | IOException e) { throw new CryptographyException(e); } }
From source file:cl.niclabs.tscrypto.common.encryption.KeyChain.java
public byte[] sign(String rsaKeyAlias, byte[] data) throws UnrecoverableEntryException, NoSuchAlgorithmException, KeyStoreException, InvalidKeyException, SignatureException { Signature sign = Signature.getInstance("SHA1WithRsa"); sign.initSign(getPrivateKey(rsaKeyAlias)); sign.update(data); byte[] signature = sign.sign(); return signature; }
From source file:com.xinferin.licensing.LicenceActivator.java
/** * Verifies the signature for the given bytes using the public key. * @param signature Signature/*from w ww . j a v a 2 s .c o m*/ * @param data Data that was signed * @return boolean True if valid signature else false * @throws Exception */ public boolean verifySignature(byte[] signature, byte[] data) throws Exception { try { initialiseKeys(); Signature signatureInstance = Signature.getInstance("SHA1withRSA"); signatureInstance.initVerify(publicKey); signatureInstance.update(data); return signatureInstance.verify(signature); } catch (NoSuchAlgorithmException e) { throw new Exception("There is no such algorithm. Please check the JDK ver." + e.getCause()); } catch (SignatureException e) { throw new Exception("There is a problem with the signature provided " + e.getCause()); } }
From source file:com.streamsets.lib.security.util.DataSignature.java
public Signer getSigner(final PrivateKey privateKey) { return new Signer() { @Override/* w w w . ja v a2 s. c o m*/ public byte[] sign(byte[] data) throws GeneralSecurityException { Signature signer = Signature.getInstance("SHA1withDSA"); signer.initSign(privateKey); signer.update(data); return signer.sign(); } }; }