@Test public void testRawPubKey() throws Exception{ String privKey = "nXCriWW3w9msxnrtOQYlYb+R51pI8zZyLTLhR8hxggk="; String pubKey = "BOg4fylDlzNxMFFTvtQBRsakfxaBJBPJf25sx8Iaim8v3h0ml9mnNCrUVJjBAeXyeGAX69NbAxbaAkNHT+6gJtU="; byte[] privKeyBytes = Base64.decodeBase64(privKey); byte[] pubKeysBytes = Base64.decodeBase64(pubKey); PublicKey pub = KeyCodec.getPubKeyFromCurve(pubKeysBytes, "secp256r1"); PrivateKey priv = KeyCodec.getPrivKeyFromCurve(privKeyBytes, "secp256r1"); assertNotNull(pub); assertNotNull(priv); String signature = "MEQCIAwtk4DStr2MqkrAlOVG+nyQxbS6tnBpVi7OcKCm8/5lAiBjVsv+b+7nI/306iNHrso/ruOaxY8IJy3jw2/zr17JEQ=="; BigInteger[] rs = Asn1.decodeToBigIntegerArray(Base64.decodeBase64(signature)); byte[] dataForSigning = Base64.decodeBase64("VGhpcyBpcyBzb21lIHJhbmRvbSBkYXRhIHRvIGJlIHNpZ25lZCBieSBhIHByaXZhdGUga2V5IGFuZCB0aGVuIHZlcmlmaWVkLg"); MessageDigest md = MessageDigest.getInstance("SHA-256"); md.update(dataForSigning); dataForSigning = md.digest(); boolean verify = NamedCurve.verify(KeyCodec.getKeyAsRawBytes((BCECPublicKey)pub), dataForSigning, rs); assertTrue(verify); }
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()); }
NamedCurve { 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()); } }
NamedCurve { 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()); }  }
NamedCurve { 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()); }  static BigInteger[] signAndFromatToRS(PrivateKey priv, byte[] input); static boolean verify(byte[] pub, byte[] dataForSigning,
			BigInteger[] rs); static boolean verifyUsingSecp256k1(byte[] pub, byte[] dataForSigning,
			BigInteger[] rs); static boolean verify(PublicKey pub, byte[] dataForSigning,
			byte[] signature); static boolean checkSignature(PublicKey publicKey,
			byte[] signedBytes, byte[] signature); static byte[] sign(byte[] signedData, PrivateKey privateKey); }
NamedCurve { 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()); }  static BigInteger[] signAndFromatToRS(PrivateKey priv, byte[] input); static boolean verify(byte[] pub, byte[] dataForSigning,
			BigInteger[] rs); static boolean verifyUsingSecp256k1(byte[] pub, byte[] dataForSigning,
			BigInteger[] rs); static boolean verify(PublicKey pub, byte[] dataForSigning,
			byte[] signature); static boolean checkSignature(PublicKey publicKey,
			byte[] signedBytes, byte[] signature); static byte[] sign(byte[] signedData, PrivateKey privateKey);  }