/** * Sign a string using the private key * @param stringToBeSigned * @param signingKey * @return * @throws GeneralSecurityException */ public static byte[] sign(String stringToBeSigned, PrivateKey signingKey) throws GeneralSecurityException { if (stringToBeSigned == null) throw new IllegalArgumentException(ErrorCodes.NULL_ARGUMENT + "stringToBeSigned"); if (signingKey == null) throw new IllegalArgumentException(ErrorCodes.NULL_ARGUMENT + "signingKey"); String algo = signingKey.getAlgorithm(); Signature sig = getSignature(algo); sig.initSign(signingKey); sig.update(stringToBeSigned.getBytes()); return sig.sign(); }
/** * Sign a string using the private key * @param stringToBeSigned * @param signingKey * @return * @throws GeneralSecurityException */ public static byte[] sign(String stringToBeSigned, PrivateKey signingKey) throws GeneralSecurityException { if (stringToBeSigned == null) throw new IllegalArgumentException(ErrorCodes.NULL_ARGUMENT + "stringToBeSigned"); if (signingKey == null) throw new IllegalArgumentException(ErrorCodes.NULL_ARGUMENT + "signingKey"); String algo = signingKey.getAlgorithm(); Signature sig = getSignature(algo); sig.initSign(signingKey); sig.update(stringToBeSigned.getBytes()); return sig.sign(); }
/** * Validate the signed content with the signature value * @param signedContent * @param signatureValue * @param validatingKey * @return * @throws GeneralSecurityException */ public static boolean validate(byte[] signedContent, byte[] signatureValue, PublicKey validatingKey) throws GeneralSecurityException { if (signedContent == null) throw new IllegalArgumentException(ErrorCodes.NULL_ARGUMENT + "signedContent"); if (signatureValue == null) throw new IllegalArgumentException(ErrorCodes.NULL_ARGUMENT + "signatureValue"); if (validatingKey == null) throw new IllegalArgumentException(ErrorCodes.NULL_ARGUMENT + "validatingKey"); //We assume that the sigatureValue has the same algorithm as the public key //If not, there will be an exception anyway String algo = validatingKey.getAlgorithm(); Signature sig = getSignature(algo); sig.initVerify(validatingKey); sig.update(signedContent); return sig.verify(signatureValue); }
/** * Validate the signature using a x509 certificate * @param signedContent * @param signatureValue * @param signatureAlgorithm * @param validatingCert * @return * @throws GeneralSecurityException */ public static boolean validate(byte[] signedContent, byte[] signatureValue, String signatureAlgorithm, X509Certificate validatingCert) throws GeneralSecurityException { if (signedContent == null) throw new IllegalArgumentException(ErrorCodes.NULL_ARGUMENT + "signedContent"); if (signatureValue == null) throw new IllegalArgumentException(ErrorCodes.NULL_ARGUMENT + "signatureValue"); if (signatureAlgorithm == null) throw new IllegalArgumentException(ErrorCodes.NULL_ARGUMENT + "signatureAlgorithm"); if (validatingCert == null) throw new IllegalArgumentException(ErrorCodes.NULL_ARGUMENT + "validatingCert"); Signature sig = getSignature(signatureAlgorithm); sig.initVerify(validatingCert); sig.update(signedContent); return sig.verify(signatureValue); }
/** * Validate the signature using a x509 certificate * @param signedContent * @param signatureValue * @param signatureAlgorithm * @param validatingCert * @return * @throws GeneralSecurityException */ public static boolean validate(byte[] signedContent, byte[] signatureValue, String signatureAlgorithm, X509Certificate validatingCert) throws GeneralSecurityException { if (signedContent == null) throw new IllegalArgumentException(ErrorCodes.NULL_ARGUMENT + "signedContent"); if (signatureValue == null) throw new IllegalArgumentException(ErrorCodes.NULL_ARGUMENT + "signatureValue"); if (signatureAlgorithm == null) throw new IllegalArgumentException(ErrorCodes.NULL_ARGUMENT + "signatureAlgorithm"); if (validatingCert == null) throw new IllegalArgumentException(ErrorCodes.NULL_ARGUMENT + "validatingCert"); Signature sig = getSignature(signatureAlgorithm); sig.initVerify(validatingCert); sig.update(signedContent); return sig.verify(signatureValue); }
/** * Validate the signed content with the signature value * @param signedContent * @param signatureValue * @param validatingKey * @return * @throws GeneralSecurityException */ public static boolean validate(byte[] signedContent, byte[] signatureValue, PublicKey validatingKey) throws GeneralSecurityException { if (signedContent == null) throw new IllegalArgumentException(ErrorCodes.NULL_ARGUMENT + "signedContent"); if (signatureValue == null) throw new IllegalArgumentException(ErrorCodes.NULL_ARGUMENT + "signatureValue"); if (validatingKey == null) throw new IllegalArgumentException(ErrorCodes.NULL_ARGUMENT + "validatingKey"); //We assume that the sigatureValue has the same algorithm as the public key //If not, there will be an exception anyway String algo = validatingKey.getAlgorithm(); Signature sig = getSignature(algo); sig.initVerify(validatingKey); sig.update(signedContent); return sig.verify(signatureValue); }
/** * Sign a string using the private key * * @param stringToBeSigned * @param signingKey * * @return * * @throws GeneralSecurityException */ public static byte[] sign(String stringToBeSigned, PrivateKey signingKey) throws GeneralSecurityException { if (stringToBeSigned == null) throw logger.nullArgumentError("stringToBeSigned"); if (signingKey == null) throw logger.nullArgumentError("signingKey"); String algo = signingKey.getAlgorithm(); Signature sig = getSignature(algo); sig.initSign(signingKey); sig.update(stringToBeSigned.getBytes()); return sig.sign(); }
/** * Sign a string using the private key * * @param stringToBeSigned * @param signingKey * @return * @throws GeneralSecurityException */ public static byte[] sign(String stringToBeSigned, PrivateKey signingKey) throws GeneralSecurityException { if (stringToBeSigned == null) throw logger.nullArgumentError("stringToBeSigned"); if (signingKey == null) throw logger.nullArgumentError("signingKey"); String algo = signingKey.getAlgorithm(); Signature sig = getSignature(algo); sig.initSign(signingKey); sig.update(stringToBeSigned.getBytes()); return sig.sign(); }
/** * Sign a string using the private key * * @param stringToBeSigned * @param signingKey * * @return * * @throws GeneralSecurityException */ public static byte[] sign(String stringToBeSigned, PrivateKey signingKey) throws GeneralSecurityException { if (stringToBeSigned == null) throw logger.nullArgumentError("stringToBeSigned"); if (signingKey == null) throw logger.nullArgumentError("signingKey"); String algo = signingKey.getAlgorithm(); Signature sig = getSignature(algo); sig.initSign(signingKey); sig.update(stringToBeSigned.getBytes()); return sig.sign(); }
/** * Validate the signed content with the signature value * * @param signedContent * @param signatureValue * @param validatingKey * @return * @throws GeneralSecurityException */ public static boolean validate(byte[] signedContent, byte[] signatureValue, PublicKey validatingKey) throws GeneralSecurityException { if (signedContent == null) throw logger.nullArgumentError("signedContent"); if (signatureValue == null) throw logger.nullArgumentError("signatureValue"); if (validatingKey == null) throw logger.nullArgumentError("validatingKey"); // We assume that the sigatureValue has the same algorithm as the public key // If not, there will be an exception anyway String algo = validatingKey.getAlgorithm(); Signature sig = getSignature(algo); sig.initVerify(validatingKey); sig.update(signedContent); return sig.verify(signatureValue); }
/** * Validate the signed content with the signature value * * @param signedContent * @param signatureValue * @param validatingKey * * @return * * @throws GeneralSecurityException */ public static boolean validate(byte[] signedContent, byte[] signatureValue, PublicKey validatingKey) throws GeneralSecurityException { if (signedContent == null) throw logger.nullArgumentError("signedContent"); if (signatureValue == null) throw logger.nullArgumentError("signatureValue"); if (validatingKey == null) throw logger.nullArgumentError("validatingKey"); // We assume that the sigatureValue has the same algorithm as the public key // If not, there will be an exception anyway String algo = validatingKey.getAlgorithm(); Signature sig = getSignature(algo); sig.initVerify(validatingKey); sig.update(signedContent); return sig.verify(signatureValue); }
/** * Validate the signed content with the signature value * * @param signedContent * @param signatureValue * @param validatingKey * * @return * * @throws GeneralSecurityException */ public static boolean validate(byte[] signedContent, byte[] signatureValue, PublicKey validatingKey) throws GeneralSecurityException { if (signedContent == null) throw logger.nullArgumentError("signedContent"); if (signatureValue == null) throw logger.nullArgumentError("signatureValue"); if (validatingKey == null) throw logger.nullArgumentError("validatingKey"); // We assume that the sigatureValue has the same algorithm as the public key // If not, there will be an exception anyway String algo = validatingKey.getAlgorithm(); Signature sig = getSignature(algo); sig.initVerify(validatingKey); sig.update(signedContent); return sig.verify(signatureValue); }
/** * Validate the signature using a x509 certificate * * @param signedContent * @param signatureValue * @param signatureAlgorithm * @param validatingCert * @return * @throws GeneralSecurityException */ public static boolean validate(byte[] signedContent, byte[] signatureValue, String signatureAlgorithm, X509Certificate validatingCert) throws GeneralSecurityException { if (signedContent == null) throw logger.nullArgumentError("signedContent"); if (signatureValue == null) throw logger.nullArgumentError("signatureValue"); if (signatureAlgorithm == null) throw logger.nullArgumentError("signatureAlgorithm"); if (validatingCert == null) throw logger.nullArgumentError("validatingCert"); Signature sig = getSignature(signatureAlgorithm); sig.initVerify(validatingCert); sig.update(signedContent); return sig.verify(signatureValue); }
/** * Validate the signature using a x509 certificate * * @param signedContent * @param signatureValue * @param signatureAlgorithm * @param validatingCert * * @return * * @throws GeneralSecurityException */ public static boolean validate(byte[] signedContent, byte[] signatureValue, String signatureAlgorithm, X509Certificate validatingCert) throws GeneralSecurityException { if (signedContent == null) throw logger.nullArgumentError("signedContent"); if (signatureValue == null) throw logger.nullArgumentError("signatureValue"); if (signatureAlgorithm == null) throw logger.nullArgumentError("signatureAlgorithm"); if (validatingCert == null) throw logger.nullArgumentError("validatingCert"); Signature sig = getSignature(signatureAlgorithm); sig.initVerify(validatingCert); sig.update(signedContent); return sig.verify(signatureValue); }
/** * Validate the signature using a x509 certificate * * @param signedContent * @param signatureValue * @param signatureAlgorithm * @param validatingCert * * @return * * @throws GeneralSecurityException */ public static boolean validate(byte[] signedContent, byte[] signatureValue, String signatureAlgorithm, X509Certificate validatingCert) throws GeneralSecurityException { if (signedContent == null) throw logger.nullArgumentError("signedContent"); if (signatureValue == null) throw logger.nullArgumentError("signatureValue"); if (signatureAlgorithm == null) throw logger.nullArgumentError("signatureAlgorithm"); if (validatingCert == null) throw logger.nullArgumentError("validatingCert"); Signature sig = getSignature(signatureAlgorithm); sig.initVerify(validatingCert); sig.update(signedContent); return sig.verify(signatureValue); }