/** * To efficiently verify all the data in one shot, if it is available, * use this method, which will avoid copying the data. * * Same as: *<pre> * setParameter(ONE_SHOT_MODE) * update(data) * ok = verify(signature) *</pre> * * @param data the message that was signed * @param signature of the message * @return true if the signature is valid, false otherwise * @throws SignatureException if update() already called * @see #ONE_SHOT_MODE * @since 0.9.25 */ public boolean verifyOneShot(byte[] data, byte[] signature) throws SignatureException { return verifyOneShot(data, 0, data.length, signature, 0, signature.length); }
/** * To efficiently verify all the data in one shot, if it is available, * use this method, which will avoid copying the data. * * Same as: *<pre> * setParameter(ONE_SHOT_MODE) * update(data, off, len) * ok = verify(signature) *</pre> * * @param data byte array containing the message that was signed * @param off the start of the message inside data * @param len the length of the message * @param signature of the message * @return true if the signature is valid, false otherwise * @throws SignatureException if update() already called * @see #ONE_SHOT_MODE * @since 0.9.25 */ public boolean verifyOneShot(byte[] data, int off, int len, byte[] signature) throws SignatureException { return verifyOneShot(data, off, len, signature, 0, signature.length); }
/** * To efficiently verify all the data in one shot, if it is available, * use this method, which will avoid copying the data. * * Same as: *<pre> * setParameter(ONE_SHOT_MODE) * update(data) * ok = verify(signature, sigoff, siglen) *</pre> * * @param data the message that was signed * @param signature byte array containing the signature * @param sigoff the start of the signature * @param siglen the length of the signature * @return true if the signature is valid, false otherwise * @throws SignatureException if update() already called * @see #ONE_SHOT_MODE * @since 0.9.25 */ public boolean verifyOneShot(byte[] data, byte[] signature, int sigoff, int siglen) throws SignatureException { return verifyOneShot(data, 0, data.length, signature, sigoff, siglen); }
rv = jsig.verifyOneShot(hash.getData(), sigbytes); } else { String algo = getRawAlgo(type);
/** * Generic verify any type. * * @throws GeneralSecurityException if algorithm unvailable or on other errors * @since 0.9.9 added off/len 0.9.12 */ private boolean altVerifySig(Signature signature, byte[] data, int offset, int len, SigningPublicKey verifyingKey) throws GeneralSecurityException { SigType type = signature.getType(); if (type != verifyingKey.getType()) throw new IllegalArgumentException("type mismatch sig=" + type + " key=" + verifyingKey.getType()); if (type == SigType.DSA_SHA1) return altVerifySigSHA1(signature, data, offset, len, verifyingKey); PublicKey pubKey = SigUtil.toJavaKey(verifyingKey); byte[] sigbytes = SigUtil.toJavaSig(signature); boolean rv; if (type.getBaseAlgorithm() == SigAlgo.EdDSA) { // take advantage of one-shot mode EdDSAEngine jsig = new EdDSAEngine(type.getDigestInstance()); jsig.initVerify(pubKey); rv = jsig.verifyOneShot(data, offset, len, sigbytes); } else { java.security.Signature jsig = java.security.Signature.getInstance(type.getAlgorithmName()); jsig.initVerify(pubKey); jsig.update(data, offset, len); rv = jsig.verify(sigbytes); } return rv; }
@Test public void testVerifyOneShot() throws Exception { EdDSAParameterSpec spec = EdDSANamedCurveTable.getByName(EdDSANamedCurveTable.ED_25519); EdDSAPublicKeySpec pubKey = new EdDSAPublicKeySpec(TEST_PK, spec); EdDSAEngine sgr = new EdDSAEngine(MessageDigest.getInstance(spec.getHashAlgorithm())); PublicKey vKey = new EdDSAPublicKey(pubKey); sgr.initVerify(vKey); assertThat("verifyOneShot() failed", sgr.verifyOneShot(TEST_MSG, TEST_MSG_SIG), is(true)); } }
/** * To efficiently verify all the data in one shot, if it is available, * use this method, which will avoid copying the data. * * Same as: *<pre> * setParameter(ONE_SHOT_MODE) * update(data) * ok = verify(signature) *</pre> * * @param data the message that was signed * @param signature of the message * @return true if the signature is valid, false otherwise * @throws SignatureException if update() already called * @see #ONE_SHOT_MODE */ public boolean verifyOneShot(byte[] data, byte[] signature) throws SignatureException { return verifyOneShot(data, 0, data.length, signature, 0, signature.length); }
/** * To efficiently verify all the data in one shot, if it is available, * use this method, which will avoid copying the data. * * Same as: *<pre> * setParameter(ONE_SHOT_MODE) * update(data, off, len) * ok = verify(signature) *</pre> * * @param data byte array containing the message that was signed * @param off the start of the message inside data * @param len the length of the message * @param signature of the message * @return true if the signature is valid, false otherwise * @throws SignatureException if update() already called * @see #ONE_SHOT_MODE */ public boolean verifyOneShot(byte[] data, int off, int len, byte[] signature) throws SignatureException { return verifyOneShot(data, off, len, signature, 0, signature.length); }
/** * To efficiently verify all the data in one shot, if it is available, * use this method, which will avoid copying the data. * * Same as: *<pre> * setParameter(ONE_SHOT_MODE) * update(data) * ok = verify(signature, sigoff, siglen) *</pre> * * @param data the message that was signed * @param signature byte array containing the signature * @param sigoff the start of the signature * @param siglen the length of the signature * @return true if the signature is valid, false otherwise * @throws SignatureException if update() already called * @see #ONE_SHOT_MODE */ public boolean verifyOneShot(byte[] data, byte[] signature, int sigoff, int siglen) throws SignatureException { return verifyOneShot(data, 0, data.length, signature, sigoff, siglen); }
/** * Verifies a signature. * * @param message * message * @param signature * signature * @return True if the signature is valid, otherwise false */ public static boolean verify(byte[] message, Signature signature) { if (message != null && signature != null) { // avoid null pointer exception try { if (Native.isEnabled()) { return Native.verify(message, signature.getS(), signature.getA()); } else { EdDSAEngine engine = new EdDSAEngine(); engine.initVerify(PublicKeyCache.computeIfAbsent(signature.getPublicKey())); return engine.verifyOneShot(message, signature.getS()); } } catch (Exception e) { // do nothing } } return false; }