当前位置: 首页>>代码示例>>Java>>正文


Java Signature.verify方法代码示例

本文整理汇总了Java中java.security.Signature.verify方法的典型用法代码示例。如果您正苦于以下问题:Java Signature.verify方法的具体用法?Java Signature.verify怎么用?Java Signature.verify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.security.Signature的用法示例。


在下文中一共展示了Signature.verify方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: verify

import java.security.Signature; //导入方法依赖的package包/类
private static void verify(Provider provider, String alg, PublicKey key,
        byte[] data, byte[] sig, boolean result) throws Exception {
    Signature s = Signature.getInstance(alg, provider);
    s.initVerify(key);
    boolean r;
    s.update(data);
    r = s.verify(sig);
    if (r != result) {
        throw new Exception("Result mismatch, actual: " + r);
    }
    s.update(data);
    r = s.verify(sig);
    if (r != result) {
        throw new Exception("Result mismatch, actual: " + r);
    }
    System.out.println("Passed");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:TestECDSA.java

示例2: validateSignBySoft256

import java.security.Signature; //导入方法依赖的package包/类
public static boolean validateSignBySoft256(PublicKey publicKey,
		byte[] signData, byte[] srcData) throws Exception {
	Signature st = Signature.getInstance(BC_PROV_ALGORITHM_SHA256RSA, "BC");
	st.initVerify(publicKey);
	st.update(srcData);
	return st.verify(signData);
}
 
开发者ID:wangfei0904306,项目名称:unionpay,代码行数:8,代码来源:SecureUtil.java

示例3: testInvalidSignature

import java.security.Signature; //导入方法依赖的package包/类
private static void testInvalidSignature(KeyPair kp1, KeyPair kp2) throws Exception {
    System.out.println("Testing signature with incorrect key...");
    Signature sig = Signature.getInstance("MD5withRSA", provider);
    sig.initSign(kp1.getPrivate());
    byte[] data = new byte[100];
    sig.update(data);
    byte[] signature = sig.sign();
    sig.initVerify(kp1.getPublic());
    sig.update(data);
    if (sig.verify(signature) == false) {
        throw new Exception("verification failed");
    }
    sig.initVerify(kp2.getPublic());
    sig.update(data);
    // verify needs to return false and not throw an Exception
    if (sig.verify(signature)) {
        throw new Exception("verification unexpectedly succeeded");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:TestKeyPairGenerator.java

示例4: createDecoder

import java.security.Signature; //导入方法依赖的package包/类
@Override
public OneWayCodec createDecoder() throws Exception {
    final Signature signature = Signature.getInstance(signatureAlgorithmName);
    signature.initVerify(keyPair.getPublic());

    return new OneWayCodec() {

        @Override
        public byte[] code(final byte[] data) throws Exception {
            final int dataLen = data.length - signatureLength;
            signature.update(data, 0, dataLen);
            if (!signature.verify(data, dataLen, signatureLength)) {
                throw new FlowStateStorageException("Invalid signature");
            }
            final byte[] b = new byte[dataLen];
            System.arraycopy(data, 0, b, 0, dataLen);
            return b;
        }
    };
}
 
开发者ID:szegedi,项目名称:spring-web-jsflow,代码行数:21,代码来源:IntegrityCodec.java

示例5: verify

import java.security.Signature; //导入方法依赖的package包/类
/**
 * Verifies that this CRL was signed using the
 * private key that corresponds to the given public key,
 * and that the signature verification was computed by
 * the given provider. Note that the specified Provider object
 * does not have to be registered in the provider list.
 *
 * @param key the PublicKey used to carry out the verification.
 * @param sigProvider the signature provider.
 *
 * @exception NoSuchAlgorithmException on unsupported signature
 * algorithms.
 * @exception InvalidKeyException on incorrect key.
 * @exception SignatureException on signature errors.
 * @exception CRLException on encoding errors.
 */
public synchronized void verify(PublicKey key, Provider sigProvider)
        throws CRLException, NoSuchAlgorithmException, InvalidKeyException,
        SignatureException {

    if (signedCRL == null) {
        throw new CRLException("Uninitialized CRL");
    }
    Signature sigVerf = null;
    if (sigProvider == null) {
        sigVerf = Signature.getInstance(sigAlgId.getName());
    } else {
        sigVerf = Signature.getInstance(sigAlgId.getName(), sigProvider);
    }
    sigVerf.initVerify(key);

    if (tbsCertList == null) {
        throw new CRLException("Uninitialized CRL");
    }

    sigVerf.update(tbsCertList, 0, tbsCertList.length);

    if (!sigVerf.verify(signature)) {
        throw new SignatureException("Signature does not match.");
    }
    verifiedPublicKey = key;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:43,代码来源:X509CRLImpl.java

示例6: verify

import java.security.Signature; //导入方法依赖的package包/类
/**
 * 
 * if has performance problem ,change Signature to ThreadLocal instance  
 * @param publicKey public key after base64 encode 
 * @param sign 签名
 * @param content original content 
 * @return verify result
 * @throws NoSuchAlgorithmException
 * @throws InvalidKeySpecException
 * @throws InvalidKeyException
 * @throws SignatureException
 */
public static boolean verify(String publicKey, String sign, String content)
    throws NoSuchAlgorithmException, InvalidKeySpecException, InvalidKeyException, SignatureException {
  if (null == kf) {
    throw new NoSuchAlgorithmException(RSA_ALG + " KeyFactory not available");
  }
  byte[] bytes = decoder.decode(publicKey);
  X509EncodedKeySpec keySpec = new X509EncodedKeySpec(bytes);
  PublicKey pubKey = kf.generatePublic(keySpec);
  Signature signature = Signature.getInstance(SIGN_ALG);
  signature.initVerify(pubKey);
  signature.update(content.getBytes());
  return signature.verify(decoder.decode(sign));
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:26,代码来源:RSAUtils.java

示例7: validateSignBySoft

import java.security.Signature; //导入方法依赖的package包/类
public static boolean validateSignBySoft(PublicKey publicKey,
		byte[] signData, byte[] srcData) throws Exception {
	Signature st = Signature.getInstance(BC_PROV_ALGORITHM_SHA1RSA, "BC");
	st.initVerify(publicKey);
	st.update(srcData);
	return st.verify(signData);
}
 
开发者ID:wangfei0904306,项目名称:unionpay,代码行数:8,代码来源:SecureUtil.java

示例8: testSignAndVerify

import java.security.Signature; //导入方法依赖的package包/类
private static void testSignAndVerify(String alg, KeyPair kp, Provider p) throws Exception {
    Signature s = Signature.getInstance(alg, p);
    s.initSign(kp.getPrivate());
    s.update(data);
    byte[] result = s.sign();

    s.initVerify(kp.getPublic());
    s.update(data);
    if (!s.verify(result)) {
        throw new Exception("Error: Signature verification failed");
    }
    System.out.println(p.getName() + ": " + alg + " Passed");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:TestECDSA2.java

示例9: verify

import java.security.Signature; //导入方法依赖的package包/类
protected static boolean verify(Class signatureClass, byte[] signatureData, Object entity, User signee, Timestamp timestamp, int depth, StringBuilder comment) throws Exception {
	Signature signature = getSignature();
	signature.initVerify(CryptoUtil.getPublicKey(signee.getKeyPair().getPublicKey()));
	updateSignature(entity, getEntitySignatures(signatureClass, entity.getClass(), depth), signature, signee, timestamp, comment);
	//FileUtils.writeStringToFile(new java.io.File("d:\\ctsms\\verify_" + timestamp.getTime() + ".txt"),comment.toString());
	return signature.verify(signatureData);
}
 
开发者ID:phoenixctms,项目名称:ctsms,代码行数:8,代码来源:EntitySignature.java

示例10: verify

import java.security.Signature; //导入方法依赖的package包/类
public void verify(PublicKey key, String sigProvider)
    throws CRLException, NoSuchAlgorithmException,
        InvalidKeyException, NoSuchProviderException, SignatureException
{
    if (!c.getSignatureAlgorithm().equals(c.getTBSCertList().getSignature()))
    {
        throw new CRLException("Signature algorithm on CertificateList does not match TBSCertList.");
    }

    Signature sig;

    if (sigProvider != null)
    {
        sig = Signature.getInstance(getSigAlgName(), sigProvider);
    }
    else
    {
        sig = Signature.getInstance(getSigAlgName());
    }

    sig.initVerify(key);
    sig.update(this.getTBSCertList());

    if (!sig.verify(this.getSignature()))
    {
        throw new SignatureException("CRL does not verify with supplied public key.");
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:29,代码来源:X509CRLObject.java

示例11: testSignature

import java.security.Signature; //导入方法依赖的package包/类
private static void testSignature(String algorithm, PrivateKey privateKey,
        PublicKey publicKey) throws Exception {
    System.out.println("Testing " + algorithm + "...");
    Signature s = Signature.getInstance(algorithm, provider);
    s.initSign(privateKey);
    s.update(data);
    byte[] sig = s.sign();
    s.initVerify(publicKey);
    s.update(data);
    boolean result = s.verify(sig);
    if (result == false) {
        throw new Exception("Verification failed");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:TestKeyPairGenerator.java

示例12: verify

import java.security.Signature; //导入方法依赖的package包/类
/**
 * 校验数字签名
 *
 * @param data      加密数据
 * @param publicKey 公钥
 * @param sign      数字签名
 * @return
 * @throws Exception
 */
public static boolean verify(byte[] data, String publicKey, String sign)
        throws Exception {

    byte[] keyBytes = BASE64.decode(publicKey); // 解密由base64编码的公钥
    X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes);  // 构造X509EncodedKeySpec对象
    KeyFactory keyFactory = KeyFactory.getInstance(Algorithm.RSA.getType());  // KEY_ALGORITHM 指定的加密算法
    PublicKey pubKey = keyFactory.generatePublic(keySpec);   // 取公钥对象

    Signature signature = Signature.getInstance(SIGNATURE_ALGORITHM);
    signature.initVerify(pubKey);
    signature.update(data);

    return signature.verify(BASE64.decode(sign));
}
 
开发者ID:lzmlsfe,项目名称:19porn,代码行数:24,代码来源:Codec.java

示例13: verify

import java.security.Signature; //导入方法依赖的package包/类
public boolean verify() throws NoSuchAlgorithmException,
        NoSuchProviderException, InvalidKeySpecException,
        InvalidKeyException, SignatureException {
    final X509EncodedKeySpec pubKeySpec = new X509EncodedKeySpec(encKey);
    final KeyFactory keyFactory = KeyFactory.getInstance("DSA", "SUN");
    final PublicKey pubKey = keyFactory.generatePublic(pubKeySpec);
    final byte[] sigToVerify = sign;
    final Signature sig = Signature.getInstance("SHA1withDSA", "SUN");
    sig.initVerify(pubKey);
    sig.update(data, 0, data.length);
    final boolean verifies = sig.verify(sigToVerify);
    return verifies;
}
 
开发者ID:Vitaliy-Yakovchuk,项目名称:ramus,代码行数:14,代码来源:KeyVerificator.java

示例14: PKCS10

import java.security.Signature; //导入方法依赖的package包/类
/**
 * Parses an encoded, signed PKCS #10 certificate request, verifying
 * the request's signature as it does so.  This constructor would
 * typically be used by a Certificate Authority, from which a new
 * certificate would then be constructed.
 *
 * @param data the DER-encoded PKCS #10 request.
 * @exception IOException for low level errors reading the data
 * @exception SignatureException when the signature is invalid
 * @exception NoSuchAlgorithmException when the signature
 *  algorithm is not supported in this environment
 */
public PKCS10(byte[] data)
throws IOException, SignatureException, NoSuchAlgorithmException {
    DerInputStream  in;
    DerValue[]      seq;
    AlgorithmId     id;
    byte[]          sigData;
    Signature       sig;

    encoded = data;

    //
    // Outer sequence:  request, signature algorithm, signature.
    // Parse, and prepare to verify later.
    //
    in = new DerInputStream(data);
    seq = in.getSequence(3);

    if (seq.length != 3)
        throw new IllegalArgumentException("not a PKCS #10 request");

    data = seq[0].toByteArray();            // reusing this variable
    id = AlgorithmId.parse(seq[1]);
    sigData = seq[2].getBitString();

    //
    // Inner sequence:  version, name, key, attributes
    //
    BigInteger      serial;
    DerValue        val;

    serial = seq[0].data.getBigInteger();
    if (!serial.equals(BigInteger.ZERO))
        throw new IllegalArgumentException("not PKCS #10 v1");

    subject = new X500Name(seq[0].data);
    subjectPublicKeyInfo = X509Key.parse(seq[0].data.getDerValue());

    // Cope with a somewhat common illegal PKCS #10 format
    if (seq[0].data.available() != 0)
        attributeSet = new PKCS10Attributes(seq[0].data);
    else
        attributeSet = new PKCS10Attributes();

    if (seq[0].data.available() != 0)
        throw new IllegalArgumentException("illegal PKCS #10 data");

    //
    // OK, we parsed it all ... validate the signature using the
    // key and signature algorithm we found.
    //
    try {
        sigAlg = id.getName();
        sig = Signature.getInstance(sigAlg);
        sig.initVerify(subjectPublicKeyInfo);
        sig.update(data);
        if (!sig.verify(sigData))
            throw new SignatureException("Invalid PKCS #10 signature");
    } catch (InvalidKeyException e) {
        throw new SignatureException("invalid key");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:74,代码来源:PKCS10.java

示例15: PKCS10

import java.security.Signature; //导入方法依赖的package包/类
/**
 * Parses an encoded, signed PKCS #10 certificate request, verifying
 * the request's signature as it does so.  This constructor would
 * typically be used by a Certificate Authority, from which a new
 * certificate would then be constructed.
 *
 * @param data the DER-encoded PKCS #10 request.
 * @exception IOException for low level errors reading the data
 * @exception SignatureException when the signature is invalid
 * @exception NoSuchAlgorithmException when the signature
 *  algorithm is not supported in this environment
 */
public PKCS10(byte[] data)
throws IOException, SignatureException, NoSuchAlgorithmException {
    DerInputStream  in;
    DerValue[]      seq;
    AlgorithmId     id;
    byte[]          sigData;
    Signature       sig;

    encoded = data;

    //
    // Outer sequence:  request, signature algorithm, signature.
    // Parse, and prepare to verify later.
    //
    in = new DerInputStream(data);
    seq = in.getSequence(3);

    if (seq.length != 3)
        throw new IllegalArgumentException("not a PKCS #10 request");

    data = seq[0].toByteArray();            // reusing this variable
    id = AlgorithmId.parse(seq[1]);
    sigData = seq[2].getBitString();

    //
    // Inner sequence:  version, name, key, attributes
    //
    BigInteger      serial;
    DerValue        val;

    serial = seq[0].data.getBigInteger();
    if (!serial.equals(BigInteger.ZERO))
        throw new IllegalArgumentException("not PKCS #10 v1");

    subject = new X500Name(seq[0].data);
    subjectPublicKeyInfo = X509Key.parse(seq[0].data.getDerValue());

    // Cope with a somewhat common illegal PKCS #10 format
    if (seq[0].data.available() != 0)
        attributeSet = new PKCS10Attributes(seq[0].data);
    else
        attributeSet = new PKCS10Attributes();

    if (seq[0].data.available() != 0)
        throw new IllegalArgumentException("illegal PKCS #10 data");

    //
    // OK, we parsed it all ... validate the signature using the
    // key and signature algorithm we found.
    //
    try {
        sig = Signature.getInstance(id.getName());
        sig.initVerify(subjectPublicKeyInfo);
        sig.update(data);
        if (!sig.verify(sigData))
            throw new SignatureException("Invalid PKCS #10 signature");
    } catch (InvalidKeyException e) {
        throw new SignatureException("invalid key");
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:73,代码来源:PKCS10.java


注:本文中的java.security.Signature.verify方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。