@Test public void signatureAndPubKey() throws InvalidKeySpecException, NoSuchAlgorithmException, NoSuchProviderException, IOException, Exception { String signatureB64 = "MEYCIQCQwRfcpxCPjqhg00JEcaSVU3VpG_X4vNO0oRHBOBvEyQIhALFn0S_nZcj3ynUgo8FirS7Ke2UDkRXCDSmuKIVrcUgx"; String pubKeyB64 = "MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEIeVW7JZYG31LXlWdz2ShKr5YH-Ms-L2lZvVXxTUzTyX3Cenl9_T1VRUa-oBfzn4FTpI16HzET-mhvoomuRcttw"; String dataForSigningStr = "BD6OAAsuCQBEQUI4IzgwMTEOLgUAAQABAgAPLiAAbFLbBK0MSSBEPYNO853JoMXlLw4T6yXp4FLPtP5aBnwKLiAA3WTfNdfUxBvSyweKIaDZNtaAlDRQ5-B4DBDcE5y7O0QQLgAACS4gAAHDA1An8EYamydS_Q8tJGT5Q4NDqtJ6PHUCbMOJ0v-qDS4EAAAAAAA"; byte[] dataForSigning = SHA.sha(Base64.decodeBase64(dataForSigningStr), "SHA-256"); assertTrue(NamedCurve .verify(KeyCodec.getKeyAsRawBytes(pubKeyB64), dataForSigning, Asn1.decodeToBigIntegerArray(Base64 .decodeBase64(signatureB64)))); }
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);  }