Here are the examples of the java api class com.google.bitcoin.bouncycastle.crypto.params.ECPublicKeyParameters taken from open source projects.
1. ECKey#verify()
Project: bitcoin-android
File: ECKey.java
File: ECKey.java
/** * Verifies the given ASN.1 encoded ECDSA signature against a hash using the public key. * @param data Hash of the data to verify. * @param signature ASN.1 encoded signature. * @param pub The public key bytes to use. */ public static boolean verify(byte[] data, byte[] signature, byte[] pub) { ECDSASigner signer = new ECDSASigner(); ECPublicKeyParameters params = new ECPublicKeyParameters(ecParams.getCurve().decodePoint(pub), ecParams); signer.init(false, params); try { ASN1InputStream decoder = new ASN1InputStream(signature); DERSequence seq = (DERSequence) decoder.readObject(); DERInteger r = (DERInteger) seq.getObjectAt(0); DERInteger s = (DERInteger) seq.getObjectAt(1); decoder.close(); return signer.verifySignature(data, r.getValue(), s.getValue()); } catch (IOException e) { throw new RuntimeException(e); } }
2. ECNRSigner#verifySignature()
Project: bitcoin-android
File: ECNRSigner.java
File: ECNRSigner.java
// Section 7.2.6 ECVP-NR, pg 35 /** * return true if the value r and s represent a signature for the * message passed in. Generally, the order of the curve should be at * least as long as the hash of the message of interest, and with * ECNR, it *must* be at least as long. But just in case the signer * applied mod(n) to the longer digest, this implementation will * apply mod(n) during verification. * * @param digest the digest to be verified. * @param r the r value of the signature. * @param s the s value of the signature. * @exception DataLengthException if the digest is longer than the key allows */ public boolean verifySignature(byte[] digest, BigInteger r, BigInteger s) { if (this.forSigning) { throw new IllegalStateException("not initialised for verifying"); } ECPublicKeyParameters pubKey = (ECPublicKeyParameters) key; BigInteger n = pubKey.getParameters().getN(); int nBitLength = n.bitLength(); BigInteger e = new BigInteger(1, digest); int eBitLength = e.bitLength(); if (eBitLength > nBitLength) { throw new DataLengthException("input too large for ECNR key."); } // r in the range [1,n-1] if (r.compareTo(ECConstants.ONE) < 0 || r.compareTo(n) >= 0) { return false; } // s in the range [0,n-1] NB: ECNR spec says 0 if (s.compareTo(ECConstants.ZERO) < 0 || s.compareTo(n) >= 0) { return false; } // compute P = sG + rW ECPoint G = pubKey.getParameters().getG(); ECPoint W = pubKey.getQ(); // calculate P using Bouncy math ECPoint P = ECAlgorithms.sumOfTwoMultiplies(G, s, W, r); BigInteger x = P.getX().toBigInteger(); BigInteger t = r.subtract(x).mod(n); return t.equals(e); }
3. ECDHCBasicAgreement#calculateAgreement()
Project: bitcoin-android
File: ECDHCBasicAgreement.java
File: ECDHCBasicAgreement.java
public BigInteger calculateAgreement(CipherParameters pubKey) { ECPublicKeyParameters pub = (ECPublicKeyParameters) pubKey; ECDomainParameters params = pub.getParameters(); ECPoint P = pub.getQ().multiply(params.getH().multiply(key.getD())); return P.getX().toBigInteger(); }
4. ECDHBasicAgreement#calculateAgreement()
Project: bitcoin-android
File: ECDHBasicAgreement.java
File: ECDHBasicAgreement.java
public BigInteger calculateAgreement(CipherParameters pubKey) { ECPublicKeyParameters pub = (ECPublicKeyParameters) pubKey; ECPoint P = pub.getQ().multiply(key.getD()); return P.getX().toBigInteger(); }