Esempio n. 1
0
 /**
  * @param privateKey
  * @param data
  * @return
  * @throws SignatureException
  * @throws NoSuchAlgorithmException
  * @throws InvalidKeyException
  */
 public static byte[] sign(PrivateKey privateKey, byte[] data) throws CryptoException {
   try {
     Signature sig = Signature.getInstance(ALGO, "BC");
     sig.initSign(privateKey);
     sig.update(data);
     return sig.sign();
   } catch (SignatureException
       | NoSuchProviderException
       | InvalidKeyException
       | NoSuchAlgorithmException e) {
     throw new CryptoException("Signing failed. " + e.getMessage());
   }
 }
Esempio n. 2
0
 /**
  * @param publicKey
  * @param data
  * @param signature
  * @return
  * @throws NoSuchAlgorithmException
  * @throws InvalidKeyException
  * @throws SignatureException
  */
 public static boolean verify(PublicKey publicKey, byte[] data, byte[] signature)
     throws CryptoException {
   try {
     Signature sig = Signature.getInstance(ALGO, "BC");
     sig.initVerify(publicKey);
     sig.update(data);
     return sig.verify(signature);
   } catch (SignatureException
       | NoSuchProviderException
       | InvalidKeyException
       | NoSuchAlgorithmException e) {
     throw new CryptoException("Signature verification failed. " + e.getMessage());
   }
 }