use of java.security.Signature in project spring-boot by spring-projects.
the class TokenValidator method hasValidSignature.
private boolean hasValidSignature(Token token, String key) {
try {
PublicKey publicKey = getPublicKey(key);
Signature signature = Signature.getInstance("SHA256withRSA");
signature.initVerify(publicKey);
signature.update(token.getContent());
return signature.verify(token.getSignature());
} catch (GeneralSecurityException ex) {
return false;
}
}
use of java.security.Signature in project robovm by robovm.
the class OpenSSLX509Certificate method verifyInternal.
private void verifyInternal(PublicKey key, String sigProvider) throws CertificateException, NoSuchAlgorithmException, InvalidKeyException, NoSuchProviderException, SignatureException {
String sigAlg = getSigAlgName();
if (sigAlg == null) {
sigAlg = getSigAlgOID();
}
final Signature sig;
if (sigProvider == null) {
sig = Signature.getInstance(sigAlg);
} else {
sig = Signature.getInstance(sigAlg, sigProvider);
}
sig.initVerify(key);
sig.update(getTBSCertificate());
if (!sig.verify(getSignature())) {
throw new SignatureException("signature did not verify");
}
}
use of java.security.Signature in project robovm by robovm.
the class JcaContentVerifierProviderBuilder method createSignatureStream.
private SignatureOutputStream createSignatureStream(AlgorithmIdentifier algorithm, PublicKey publicKey) throws OperatorCreationException {
try {
Signature sig = helper.createSignature(algorithm);
sig.initVerify(publicKey);
return new SignatureOutputStream(sig);
} catch (GeneralSecurityException e) {
throw new OperatorCreationException("exception on setup: " + e, e);
}
}
use of java.security.Signature in project robovm by robovm.
the class OperatorHelper method createRawSignature.
public Signature createRawSignature(AlgorithmIdentifier algorithm) {
Signature sig;
try {
String algName = getSignatureName(algorithm);
algName = "NONE" + algName.substring(algName.indexOf("WITH"));
sig = helper.createSignature(algName);
// the AlgorithmIdentifier parameters field MUST contain RSASSA-PSS-params.
if (algorithm.getAlgorithm().equals(PKCSObjectIdentifiers.id_RSASSA_PSS)) {
AlgorithmParameters params = helper.createAlgorithmParameters(algName);
params.init(algorithm.getParameters().toASN1Primitive().getEncoded(), "ASN.1");
PSSParameterSpec spec = (PSSParameterSpec) params.getParameterSpec(PSSParameterSpec.class);
sig.setParameter(spec);
}
} catch (Exception e) {
return null;
}
return sig;
}
use of java.security.Signature in project robovm by robovm.
the class SignatureTest method testVerify_SHA1withDSA_Key_Success.
public void testVerify_SHA1withDSA_Key_Success() throws Exception {
KeyFactory kf = KeyFactory.getInstance("DSA");
DSAPublicKeySpec pubKeySpec = new DSAPublicKeySpec(DSA_pub, DSA_P, DSA_Q, DSA_G);
PublicKey pubKey = kf.generatePublic(pubKeySpec);
Signature sig = Signature.getInstance("SHA1withDSA");
sig.initVerify(pubKey);
sig.update(Vector2Data);
assertTrue("Signature must verify correctly", sig.verify(SHA1withDSA_Vector2Signature));
}
Aggregations