List of usage examples for org.bouncycastle.crypto.params ECPublicKeyParameters ECPublicKeyParameters
public ECPublicKeyParameters(ECPoint q, ECDomainParameters parameters)
From source file:ACNS.thresholdDSA.Util.java
License:Apache License
public static boolean verifySignature(byte[] message, BigInteger r, BigInteger s, byte[] pub, ECDomainParameters Curve) {//from www. java2 s . c o m ECDSASigner signer = new ECDSASigner(); ECPublicKeyParameters params = new ECPublicKeyParameters(Curve.getCurve().decodePoint(pub), Curve); signer.init(false, params); try { return signer.verifySignature(message, r, s); } catch (NullPointerException e) { // Bouncy Castle contains a bug that can cause NPEs given specially // crafted signatures. Those signatures // are inherently invalid/attack sigs so we just fail them here // rather than crash the thread. System.out.println("Caught NPE inside bouncy castle"); e.printStackTrace(); return false; } }
From source file:card.CardClient.java
License:Open Source License
/** * Get an attribute from the card/* ww w. j a va2 s. com*/ * * @param i Index of the attribute. * @return Blinded public key, blinded attribute signature and the attribute */ public BigInteger[] getAttribute(byte id, ECPoint nonce) { BigInteger[] result = new BigInteger[3]; int i = 0; while (i < attribute.length && attribute_id[i] != id) i++; if (i >= attribute.length || attribute_id[i] != id) { return null; } result[ATTRIBUTE] = attribute[i]; // generate a blinding factor b blinder = (ECPrivateKey) keyGen.generateKeyPair().getPrivate(); // blind public key, attribute signature and signed nonce try { ECDHBasicAgreement agreement = new ECDHBasicAgreement(); agreement.init(new ECPrivateKeyParameters(blinder.getD(), ecDom)); result[BLINDED_KEY] = agreement .calculateAgreement(new ECPublicKeyParameters(((ECPublicKey) keys.getPublic()).getQ(), ecDom)); result[BLINDED_SIGNATURE] = agreement .calculateAgreement(new ECPublicKeyParameters(signature[i], ecDom)); result[SIGNED_NONCE] = agreement.calculateAgreement( new ECPublicKeyParameters(nonce.multiply(((ECPrivateKey) keys.getPrivate()).getD()), ecDom)); } catch (Exception e) { e.printStackTrace(); } // return blinded public key, blinded attribute signature, blinded signed nonce, attribute return result; }
From source file:com.amazonaws.encryptionsdk.internal.DecryptionHandler.java
License:Open Source License
private PublicKey deserializeTrailingKeyFromEc(final String pubKey) throws GeneralSecurityException { final ECNamedCurveParameterSpec ecSpec; switch (cryptoAlgo_) { case ALG_AES_128_GCM_IV12_TAG16_HKDF_SHA256_ECDSA_P256: ecSpec = ECNamedCurveTable.getParameterSpec("secp256r1"); break;/*from w w w. j av a2 s . c om*/ case ALG_AES_192_GCM_IV12_TAG16_HKDF_SHA384_ECDSA_P384: case ALG_AES_256_GCM_IV12_TAG16_HKDF_SHA384_ECDSA_P384: ecSpec = ECNamedCurveTable.getParameterSpec("secp384r1"); break; default: throw new IllegalStateException("Algorithm does not support trailing signature"); } final ECPoint q = ecSpec.getCurve().decodePoint(Base64.decode(pubKey)); ECPublicKeyParameters keyParams = new ECPublicKeyParameters(q, new ECDomainParameters(ecSpec.getCurve(), ecSpec.getG(), ecSpec.getN(), ecSpec.getH())); return new BCECPublicKey("ECDSA", keyParams, ecSpec, BouncyCastleProvider.CONFIGURATION); }
From source file:com.bitsofproof.supernode.api.ECKeyPair.java
License:Apache License
public static boolean verify(byte[] hash, byte[] signature, byte[] pub) { ASN1InputStream asn1 = new ASN1InputStream(signature); try {/*from w w w . ja va 2s . co m*/ ECDSASigner signer = new ECDSASigner(); signer.init(false, new ECPublicKeyParameters(curve.getCurve().decodePoint(pub), domain)); DLSequence seq = (DLSequence) asn1.readObject(); BigInteger r = ((DERInteger) seq.getObjectAt(0)).getPositiveValue(); BigInteger s = ((DERInteger) seq.getObjectAt(1)).getPositiveValue(); return signer.verifySignature(hash, r, s); } catch (Exception e) { // threat format errors as invalid signatures return false; } finally { try { asn1.close(); } catch (IOException e) { } } }
From source file:com.cryptolib.CryptoObject.java
License:Open Source License
/** * Performs ECDH//from ww w .j ava2s . c o m */ public void createSharedEncKey(ECPublicKey key) throws CryptoSocketException { try { X9ECParameters ecP = CustomNamedCurves.getByName(curve); ECDomainParameters ecdp = new ECDomainParameters(ecP.getCurve(), ecP.getG(), ecP.getN(), ecP.getH()); ECPublicKeyParameters ecpkp = new ECPublicKeyParameters(key.getQ(), ecdp); BCECPrivateKey sk = (BCECPrivateKey) this.encKeypair.getPrivate(); ECPrivateKeyParameters ecskp = new ECPrivateKeyParameters(sk.getD(), ecdp); ECDHCBasicAgreement ba = new ECDHCBasicAgreement(); ba.init(ecskp); byte[] byteSharedSecret = ba.calculateAgreement(ecpkp).toByteArray(); byte[] byteSharedSecretSecond = new byte[byteSharedSecret.length / 2]; byte[] byteSharedSecretFirst = new byte[byteSharedSecret.length / 2]; System.arraycopy(byteSharedSecret, 0, byteSharedSecretSecond, 0, byteSharedSecretSecond.length); System.arraycopy(byteSharedSecret, byteSharedSecretSecond.length, byteSharedSecretFirst, 0, byteSharedSecretFirst.length); this.sharedSecretFirst = new SecretKeySpec(byteSharedSecretFirst, "AES"); this.sharedSecretSecond = new SecretKeySpec(byteSharedSecretSecond, "AES"); this.has_symmetric_key = true; this.enc = Cipher.getInstance("AES/GCM/NoPadding"); this.dec = Cipher.getInstance("AES/GCM/NoPadding"); } catch (IllegalStateException is) { throw new CryptoSocketException("unable to create shared encryption key, wrong state!"); } catch (NoSuchAlgorithmException nsa) { throw new CryptoSocketException("Encryption algorithm not found!"); } catch (NoSuchPaddingException nsp) { throw new CryptoSocketException("Invalid padding algorithm!"); } }
From source file:com.DSC.crypto.ECGKeyUtil.java
License:Open Source License
/** * decodePubKey A function which takes an ASN.1 encoded ECC public key Q * and returns an ECPublicKeyParameters object for the public key Q. * // w w w. ja va2 s . c o m * @param param The Elliptic Curve key parameter which contains the curve * specifications and domain parameters * @param encodedPubkey A byte array of the ASN.1 encoded public key Q * @return An ECC public key parameter for Q, ECPublicKeyParametersimplements */ static public ECPublicKeyParameters decodePubKey(byte[] encodedPubKey) { /* * Takes the encoded public key Q and decodes an X and Y value for * the point Q, then returns an ECPublicKeyParameters object for * the elliptic curve parameters specified */ return new ECPublicKeyParameters(param.getCurve().decodePoint(encodedPubKey), // Q param.getECDomainParam()); }
From source file:com.DSC.crypto.ECGKeyUtil.java
License:Open Source License
/** * decodeSignedPubKey A function which takes an ASN.1 encoded ECC public key Q * that is signed using the Elliptic Curve Gillett (ECG) Exchange key exchange * and returns an ECPublicKeyParameters object for the public key Q. * /*from w w w.jav a 2 s .c om*/ * @param param The Elliptic Curve key parameter which contains the curve * specifications and domain parameters * @param digest The digest function used to originally sign the key such as SHA256 * @param signedPubkey A byte array of the ASN.1 encoded public key Q that is signed * @return An ECC public key parameter for Q, ECPublicKeyParametersimplements */ static public ECPublicKeyParameters decodeSignedPubKey(Digest digest, byte[] signedPubKey) { /* * Retrieve the ASN.1 encoded ECC public key Q from the contents of signed public key */ byte[] encodedPubKey = new byte[signedPubKey.length - digest.getDigestSize()]; System.arraycopy(signedPubKey, 0, encodedPubKey, 0, signedPubKey.length - digest.getDigestSize()); /* * Takes the encoded public key Q and decodes an X and Y value for * the point Q, then returns an ECPublicKeyParameters object for * the elliptic curve parameters specified */ return new ECPublicKeyParameters(param.getCurve().decodePoint(encodedPubKey), // Q param.getECDomainParam()); }
From source file:com.github.horrorho.inflatabledonkey.crypto.ec.ECCurvePoint.java
License:Open Source License
public boolean verifySignature(byte[] message, BigInteger r, BigInteger s) { ECDomainParameters ecDomainParameters = ECAssistant.ecDomainParametersFrom(x9ECParameters); ECPublicKeyParameters ecPublicKeyParameters = new ECPublicKeyParameters(Q, ecDomainParameters); ECDSASigner signer = new ECDSASigner(); signer.init(false, ecPublicKeyParameters); return signer.verifySignature(message, r, s); }
From source file:com.github.horrorho.inflatabledonkey.crypto.eckey.DefaultECPublicKey.java
License:Open Source License
@Override public boolean verifySignature(byte[] message, BigInteger r, BigInteger s) { ECDomainParameters ecDomainParameters = ECAssistant.ecDomainParametersFrom(x9ECParameters); ECPublicKeyParameters ecPublicKeyParameters = new ECPublicKeyParameters(Q, ecDomainParameters); ECDSASigner signer = new ECDSASigner(); signer.init(false, ecPublicKeyParameters); return signer.verifySignature(message, r, s); }
From source file:com.google.bitcoin.core.ECKey.java
License:Apache License
/** * <p>Verifies the given ECDSA signature against the message bytes using the public key bytes.</p> * //ww w. j av a 2s. c o m * <p>When using native ECDSA verification, data must be 32 bytes, and no element may be * larger than 520 bytes.</p> * * @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, ECDSASignature signature, byte[] pub) { if (FAKE_SIGNATURES) return true; if (NativeSecp256k1.enabled) return NativeSecp256k1.verify(data, signature.encodeToDER(), pub); ECDSASigner signer = new ECDSASigner(); ECPublicKeyParameters params = new ECPublicKeyParameters(CURVE.getCurve().decodePoint(pub), CURVE); signer.init(false, params); try { return signer.verifySignature(data, signature.r, signature.s); } catch (NullPointerException e) { // Bouncy Castle contains a bug that can cause NPEs given specially crafted signatures. Those signatures // are inherently invalid/attack sigs so we just fail them here rather than crash the thread. log.error("Caught NPE inside bouncy castle"); e.printStackTrace(); return false; } }