/** Decompress a compressed public key (x co-ord and low-bit of y-coord). */ private static ECPoint decompressKey(BigInteger xBN, boolean yBit) { X9IntegerConverter x9 = new X9IntegerConverter(); byte[] compEnc = x9.integerToBytes(xBN, 1 + x9.getByteLength(CURVE.getCurve())); compEnc[0] = (byte)(yBit ? 0x03 : 0x02); return CURVE.getCurve().decodePoint(compEnc); }
protected ECPoint deserializeEcPoint(ECDomainParameters parameters, byte[] bytes) { ECPoint decodePoint = parameters.getCurve().decodePoint(bytes); return decodePoint; } }
public synchronized ECPoint getPoint() { if (p == null) { p = c.decodePoint(encoding.getOctets()).normalize(); } return p; }
public static ECPoint cleanPoint(ECCurve c, ECPoint p) { ECCurve cp = p.getCurve(); if (!c.equals(cp)) { throw new IllegalArgumentException("Point must be on the same curve"); } return c.decodePoint(p.getEncoded(false)); }
ECPoint decodePoint(byte[] data) { ECCurve curve = ECNamedCurveTable.getByName(curveName).getCurve(); int compactExportSize = (curve.getFieldSize() + 7) / 8; return data.length == compactExportSize ? ECPointsCompact.decodeFPPoint(curve, data) // Compact keys support, non RFC6636 compliant. : curve.decodePoint(data); }
/** Decompress a compressed public key (x co-ord and low-bit of y-coord). */ private static ECPoint decompressKey(BigInteger xBN, boolean yBit) { X9IntegerConverter x9 = new X9IntegerConverter(); byte[] compEnc = x9.integerToBytes(xBN, 1 + x9.getByteLength(CURVE.getCurve())); compEnc[0] = (byte)(yBit ? 0x03 : 0x02); return CURVE.getCurve().decodePoint(compEnc); }
/** Decompress a compressed public key (x co-ord and low-bit of y-coord). */ private static ECPoint decompressKey(BigInteger xBN, boolean yBit) { X9IntegerConverter x9 = new X9IntegerConverter(); byte[] compEnc = x9.integerToBytes(xBN, 1 + x9.getByteLength(CURVE.getCurve())); compEnc[0] = (byte)(yBit ? 0x03 : 0x02); return CURVE.getCurve().decodePoint(compEnc); }
/** Decompress a compressed public key (x co-ord and low-bit of y-coord). */ private static ECPoint decompressKey(BigInteger xBN, boolean yBit) { X9IntegerConverter x9 = new X9IntegerConverter(); byte[] compEnc = x9.integerToBytes(xBN, 1 + x9.getByteLength(CURVE.getCurve())); compEnc[0] = (byte)(yBit ? 0x03 : 0x02); return CURVE.getCurve().decodePoint(compEnc); }
/** Decompress a compressed public key (x co-ord and low-bit of y-coord). */ private static ECPoint decompressKey(BigInteger xBN, boolean yBit) { X9IntegerConverter x9 = new X9IntegerConverter(); byte[] compEnc = x9.integerToBytes(xBN, 1 + x9.getByteLength(CURVE.getCurve())); compEnc[0] = (byte)(yBit ? 0x03 : 0x02); return CURVE.getCurve().decodePoint(compEnc); }
@Override public PublicKey deserializePublicKey(String keyString) { final ECPoint q = ecSpec.getCurve().decodePoint(Base64.getDecoder().decode(keyString)); ECPublicKeyParameters keyParams = new ECPublicKeyParameters( q, new ECDomainParameters(ecSpec.getCurve(), ecSpec.getG(), ecSpec.getN(), ecSpec.getH()) ); return new BCECPublicKey("ECDSA", keyParams, ecSpec, BouncyCastleProvider.CONFIGURATION); }
public static boolean verify(byte[] pub, byte[] dataForSigning, BigInteger[] rs) throws Exception { ECDSASigner signer = new ECDSASigner(); X9ECParameters params = SECNamedCurves.getByName("secp256r1"); ECDomainParameters ecParams = new ECDomainParameters(params.getCurve(), params.getG(), params.getN(), params.getH()); ECPublicKeyParameters pubKeyParams = new ECPublicKeyParameters(ecParams .getCurve().decodePoint(pub), ecParams); signer.init(false, pubKeyParams); return signer.verifySignature(dataForSigning, rs[0].abs(), rs[1].abs()); }
public static boolean verify(byte[] pub, byte[] dataForSigning, BigInteger[] rs) throws Exception { ECDSASigner signer = new ECDSASigner(); X9ECParameters params = SECNamedCurves.getByName("secp256r1"); ECDomainParameters ecParams = new ECDomainParameters(params.getCurve(), params.getG(), params.getN(), params.getH()); ECPublicKeyParameters pubKeyParams = new ECPublicKeyParameters(ecParams .getCurve().decodePoint(pub), ecParams); signer.init(false, pubKeyParams); return signer.verifySignature(dataForSigning, rs[0].abs(), rs[1].abs()); }
public static boolean verifyUsingSecp256k1(byte[] pub, byte[] dataForSigning, BigInteger[] rs) throws Exception { ECDSASigner signer = new ECDSASigner(); X9ECParameters params = SECNamedCurves.getByName("secp256k1"); ECDomainParameters ecParams = new ECDomainParameters(params.getCurve(), params.getG(), params.getN(), params.getH()); ECPublicKeyParameters pubKeyParams = new ECPublicKeyParameters(ecParams .getCurve().decodePoint(pub), ecParams); signer.init(false, pubKeyParams); return signer.verifySignature(dataForSigning, rs[0].abs(), rs[1].abs()); }
public static boolean verifyUsingSecp256k1(byte[] pub, byte[] dataForSigning, BigInteger[] rs) throws Exception { ECDSASigner signer = new ECDSASigner(); X9ECParameters params = SECNamedCurves.getByName("secp256k1"); ECDomainParameters ecParams = new ECDomainParameters(params.getCurve(), params.getG(), params.getN(), params.getH()); ECPublicKeyParameters pubKeyParams = new ECPublicKeyParameters(ecParams .getCurve().decodePoint(pub), ecParams); signer.init(false, pubKeyParams); return signer.verifySignature(dataForSigning, rs[0].abs(), rs[1].abs()); }
protected X9ECParameters createParameters() { byte[] S = Hex.decode("D09E8800291CB85396CC6717393284AAA0DA64BA"); ECCurve curve = configureCurve(new SecP521R1Curve()); ECPoint G = curve.decodePoint(Hex.decode("04" + "00C6858E06B70404E9CD9E3ECB662395B4429C648139053FB521F828AF606B4D3DBAA14B5E77EFE75928FE1DC127A2FFA8DE3348B3C1856A429BF97E7E31C2E5BD66" + "011839296A789A3BC0045C8A5FB42C7D1BD998F54449579B446817AFBD17273E662C97EE72995EF42640C550B9013FAD0761353C7086A272C24088BE94769FD16650")); return new X9ECParameters(curve, G, curve.getOrder(), curve.getCofactor(), S); } };
protected X9ECParameters createParameters() { byte[] S = Hex.decode("A335926AA319A27A1D00896A6773A4827ACDAC73"); ECCurve curve = configureCurve(new SecP384R1Curve()); ECPoint G = curve.decodePoint(Hex.decode("04" + "AA87CA22BE8B05378EB1C71EF320AD746E1D3B628BA79B9859F741E082542A385502F25DBF55296C3A545E3872760AB7" + "3617DE4A96262C6F5D9E98BF9292DC29F8F41DBD289A147CE9DA3113B5F0B8C00A60B1CE1D7E819D7A431D7C90EA0E5F")); return new X9ECParameters(curve, G, curve.getOrder(), curve.getCofactor(), S); } };
protected X9ECParameters createParameters() { byte[] S = Hex.decode("C49D360886E704936A6678E1139D26B7819F7E90"); ECCurve curve = configureCurve(new SecP256R1Curve()); ECPoint G = curve.decodePoint(Hex.decode("04" + "6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296" + "4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5")); return new X9ECParameters(curve, G, curve.getOrder(), curve.getCofactor(), S); } };
/** * Gets the EC public key parameters. * * @param publicKey The public key. * @return The EC public key parameters. */ public static ECPublicKeyParameters getPublicKeyParameters(final PublicKey publicKey) { final ECPoint point = SecP256K1Curve.secp256k1().getParams().getCurve().decodePoint(publicKey.getRaw()); return new ECPublicKeyParameters(point, SecP256K1Curve.secp256k1().getParams()); } }
public boolean verify(byte[] message, byte[] signature) throws Exception { ASN1InputStream asn1 = new ASN1InputStream(signature); ECDSASigner signer = new ECDSASigner(); //not for signing... signer.init(false, new ECPublicKeyParameters(curve.getCurve().decodePoint(pub), params)); DLSequence seq = (DLSequence) asn1.readObject(); BigInteger r = ((ASN1Integer) seq.getObjectAt(0)).getPositiveValue(); BigInteger s = ((ASN1Integer) seq.getObjectAt(1)).getPositiveValue(); return signer.verifySignature(message, r, s); }
@Override public boolean verify(final byte[] data, final Signature signature) { if (!this.isCanonicalSignature(signature)) { return false; } final ECDSASigner signer = this.createECDSASigner(); final ECPoint point = SecP256K1Curve.secp256k1().getParams().getCurve().decodePoint(this.keyPair.getPublicKey().getRaw()); final ECPublicKeyParameters publicKeyParameters = new ECPublicKeyParameters(point, SecP256K1Curve.secp256k1().getParams()); signer.init(false, publicKeyParameters); final byte[] hash = Hashes.sha3_256(data); return signer.verifySignature(hash, signature.getR(), signature.getS()); }