本文整理汇总了Java中org.bouncycastle.crypto.signers.ECDSASigner.init方法的典型用法代码示例。如果您正苦于以下问题:Java ECDSASigner.init方法的具体用法?Java ECDSASigner.init怎么用?Java ECDSASigner.init使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.crypto.signers.ECDSASigner
的用法示例。
在下文中一共展示了ECDSASigner.init方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: verify
import org.bouncycastle.crypto.signers.ECDSASigner; //导入方法依赖的package包/类
@Override
public boolean verify(byte[] hash, byte[] signature, byte[] publicKey) {
ASN1InputStream asn1 = new ASN1InputStream(signature);
try {
ECDSASigner signer = new ECDSASigner();
signer.init(false, new ECPublicKeyParameters(curve.getCurve().decodePoint(publicKey), domain));
DLSequence seq = (DLSequence) asn1.readObject();
BigInteger r = ((ASN1Integer) seq.getObjectAt(0)).getPositiveValue();
BigInteger s = ((ASN1Integer) seq.getObjectAt(1)).getPositiveValue();
return signer.verifySignature(hash, r, s);
} catch (Exception e) {
return false;
} finally {
try {
asn1.close();
} catch (IOException ignored) {
}
}
}
示例2: sign
import org.bouncycastle.crypto.signers.ECDSASigner; //导入方法依赖的package包/类
@Override
public byte[] sign(byte[] hash, byte[] privateKey) {
ECDSASigner signer = new ECDSASigner(new HMacDSAKCalculator(new SHA256Digest()));
signer.init(true, new ECPrivateKeyParameters(new BigInteger(privateKey), domain));
BigInteger[] signature = signer.generateSignature(hash);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
DERSequenceGenerator seq = new DERSequenceGenerator(baos);
seq.addObject(new ASN1Integer(signature[0]));
seq.addObject(new ASN1Integer(toCanonicalS(signature[1])));
seq.close();
return baos.toByteArray();
} catch (IOException e) {
return new byte[0];
}
}
示例3: verifySignature
import org.bouncycastle.crypto.signers.ECDSASigner; //导入方法依赖的package包/类
public static boolean verifySignature(byte[] sigR, byte sigS[], byte[] publicKey, byte[] message) {
try {
Security.addProvider(new BouncyCastleProvider());
ECNamedCurveParameterSpec spec = ECNamedCurveTable.getParameterSpec(SECP256K1);
ECDomainParameters domain = new ECDomainParameters(spec.getCurve(), spec.getG(), spec.getN());
ECPublicKeyParameters publicKeyParams =
new ECPublicKeyParameters(spec.getCurve().decodePoint(publicKey), domain);
ECDSASigner signer = new ECDSASigner();
signer.init(false, publicKeyParams);
return signer.verifySignature(message, new BigInteger(1, sigR), new BigInteger(1, sigS));
} catch (Exception e) {
LOGGER.error(null, e);
return false;
}
}
示例4: verifyUsingSecp256k1
import org.bouncycastle.crypto.signers.ECDSASigner; //导入方法依赖的package包/类
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());
}
示例5: curveTest
import org.bouncycastle.crypto.signers.ECDSASigner; //导入方法依赖的package包/类
@Test
public void curveTest() {
final X9ECParameters curve = NISTNamedCurves.getByName("P-384");
final ECDomainParameters domainParameters = new ECDomainParameters(
curve.getCurve(), curve.getG(), curve.getN());
final SecureRandom random = new SecureRandom();
final ECKeyPairGenerator gen = new ECKeyPairGenerator();
gen.init(new ECKeyGenerationParameters(domainParameters, random));
final AsymmetricCipherKeyPair senderPair = gen.generateKeyPair();
final ECDSASigner signer = new ECDSASigner();
signer.init(true, senderPair.getPrivate());
final byte[] message = "The magic words are squeamish ossifrage".getBytes(
Constants.ASCII);
final SHA384Digest digester = new SHA384Digest();
digester.update(message, 0, message.length);
final byte[] digest = new byte[digester.getDigestSize()];
digester.doFinal(digest, 0);
final BigInteger[] signature = signer.generateSignature(digest);
final ECDSASigner verifier = new ECDSASigner();
verifier.init(false, senderPair.getPublic());
assertTrue(verifier.verifySignature(digest, signature[0], signature[1]));
}
示例6: sign
import org.bouncycastle.crypto.signers.ECDSASigner; //导入方法依赖的package包/类
@Override
public byte[] sign (byte[] hash) throws ValidationException
{
if ( priv == null )
{
throw new ValidationException ("Need private key to sign");
}
ECDSASigner signer = new ECDSASigner (new HMacDSAKCalculator (new SHA256Digest ()));
signer.init (true, new ECPrivateKeyParameters (priv, domain));
BigInteger[] signature = signer.generateSignature (hash);
ByteArrayOutputStream s = new ByteArrayOutputStream ();
try
{
DERSequenceGenerator seq = new DERSequenceGenerator (s);
seq.addObject (new ASN1Integer (signature[0]));
seq.addObject (new ASN1Integer (signature[1]));
seq.close ();
return s.toByteArray ();
}
catch ( IOException e )
{
}
return null;
}
示例7: testECDSAKeyGenTest
import org.bouncycastle.crypto.signers.ECDSASigner; //导入方法依赖的package包/类
/**
* key generation test
*/
private void testECDSAKeyGenTest()
{
SecureRandom random = new SecureRandom();
ECCurve.Fp curve = new ECCurve.Fp(
new BigInteger("883423532389192164791648750360308885314476597252960362792450860609699839"), // q
new BigInteger("7fffffffffffffffffffffff7fffffffffff8000000000007ffffffffffc", 16), // a
new BigInteger("6b016c3bdcf18941d0d654921475ca71a9db2fb27d1d37796185c2942c0a", 16)); // b
ECDomainParameters params = new ECDomainParameters(
curve,
curve.decodePoint(Hex.decode("020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf")), // G
new BigInteger("883423532389192164791648750360308884807550341691627752275345424702807307")); // n
ECKeyPairGenerator pGen = new ECKeyPairGenerator();
ECKeyGenerationParameters genParam = new ECKeyGenerationParameters(
params,
random);
pGen.init(genParam);
AsymmetricCipherKeyPair pair = pGen.generateKeyPair();
ParametersWithRandom param = new ParametersWithRandom(pair.getPrivate(), random);
ECDSASigner ecdsa = new ECDSASigner();
ecdsa.init(true, param);
byte[] message = new BigInteger("968236873715988614170569073515315707566766479517").toByteArray();
BigInteger[] sig = ecdsa.generateSignature(message);
ecdsa.init(false, pair.getPublic());
if (!ecdsa.verifySignature(message, sig[0], sig[1]))
{
fail("signature fails");
}
}
示例8: isSignatureVerified
import org.bouncycastle.crypto.signers.ECDSASigner; //导入方法依赖的package包/类
public boolean isSignatureVerified(StellarBinaryObject serObj) {
try {
byte[] signatureBytes= (byte[]) serObj.getField(BinaryFormatField.TxnSignature);
if(signatureBytes==null){
throw new RuntimeException("The specified has no signature");
}
byte[] signingPubKeyBytes = (byte[]) serObj.getField(BinaryFormatField.SigningPubKey);
if(signingPubKeyBytes==null){
throw new RuntimeException("The specified has no public key associated to the signature");
}
StellarBinaryObject unsignedRBO = serObj.getUnsignedCopy();
byte[] hashToVerify = unsignedRBO.generateHashFromBinaryObject();
ECDSASigner signer = new ECDSASigner();
ECDSASignature signature = new ECDSASignature(signatureBytes, signingPubKeyBytes);
signer.init(false, new ECPublicKeyParameters(signature.publicSigningKey, StellarDeterministicKeyGenerator.SECP256K1_PARAMS));
return signer.verifySignature(hashToVerify, signature.r, signature.s);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例9: sign
import org.bouncycastle.crypto.signers.ECDSASigner; //导入方法依赖的package包/类
default byte[] sign(Account account) {
ECDSASigner signer = new ECDSASigner();
signer.init(true, new ECPrivateKeyParameters(new BigInteger(1, account.privateKey), ECC.secp256r1));
BigInteger[] bi = signer.generateSignature(Digest.sha256(getHashData()));// dna
byte[] signature = new byte[64];
System.arraycopy(BigIntegers.asUnsignedByteArray(32, bi[0]), 0, signature, 0, 32);
System.arraycopy(BigIntegers.asUnsignedByteArray(32, bi[1]), 0, signature, 32, 32);
return signature;
}
示例10: signAndFromatToRS
import org.bouncycastle.crypto.signers.ECDSASigner; //导入方法依赖的package包/类
/**
* UAF_ALG_SIGN_SECP256R1_ECDSA_SHA256_RAW 0x01 An ECDSA signature on the
* NIST secp256r1 curve which MUST have raw R and S buffers, encoded in
* big-endian order. I.e. [R (32 bytes), S (32 bytes)]
*
* @param priv
* - Private key
* @param input
* - Data to sign
* @return BigInteger[] - [R,S]
*/
public static BigInteger[] signAndFromatToRS(PrivateKey priv, byte[] input) {
X9ECParameters params = SECNamedCurves.getByName("secp256r1");
ECDomainParameters ecParams = new ECDomainParameters(params.getCurve(),
params.getG(), params.getN(), params.getH());
if (priv == null)
throw new IllegalStateException(
"This ECKey does not have the private key necessary for signing.");
ECDSASigner signer = new ECDSASigner();
ECPrivateKeyParameters privKey = new ECPrivateKeyParameters(
((ECPrivateKey) priv).getS(), ecParams);
signer.init(true, privKey);
BigInteger[] sigs = signer.generateSignature(input);
return sigs;
}
示例11: verify
import org.bouncycastle.crypto.signers.ECDSASigner; //导入方法依赖的package包/类
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());
}
示例12: sign
import org.bouncycastle.crypto.signers.ECDSASigner; //导入方法依赖的package包/类
/**
* Sign a hash with the private key of this key pair.
* @param transactionHash the hash to sign
* @return An {@link ECDSASignature} of the hash
*/
public ECDSASignature sign(byte[] transactionHash) {
ECDSASigner signer = new ECDSASigner(new HMacDSAKCalculator(new SHA256Digest()));
ECPrivateKeyParameters privKey = new ECPrivateKeyParameters(privateKey, Sign.CURVE);
signer.init(true, privKey);
BigInteger[] components = signer.generateSignature(transactionHash);
return new ECDSASignature(components[0], components[1]).toCanonicalised();
}
示例13: sign
import org.bouncycastle.crypto.signers.ECDSASigner; //导入方法依赖的package包/类
/**
* Sign a digest with this key.
*
* @param hash arbitrary data
* @return signature
*/
public byte[] sign(byte[] hash) {
ECDSASigner signer = new ECDSASigner(new HMacDSAKCalculator(new SHA256Digest()));
signer.init(true, new ECPrivateKeyParameters(priv, domain));
BigInteger[] signature = signer.generateSignature(hash);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
DERSequenceGenerator seq = new DERSequenceGenerator(baos);
seq.addObject(new ASN1Integer(signature[0]));
seq.addObject(new ASN1Integer(toCanonicalS(signature[1])));
seq.close();
return baos.toByteArray();
} catch (IOException e) {
}
return null;
}
示例14: signTransaction
import org.bouncycastle.crypto.signers.ECDSASigner; //导入方法依赖的package包/类
/**
* Sign data using the ECDSA algorithm.
*/
public static byte[][] signTransaction(byte[] data, byte[] privateKey) {
try {
Security.addProvider(new BouncyCastleProvider());
ECNamedCurveParameterSpec spec = ECNamedCurveTable.getParameterSpec(SECP256K1);
ECDSASigner ecdsaSigner = new ECDSASigner();
ECDomainParameters domain = new ECDomainParameters(spec.getCurve(), spec.getG(), spec.getN());
ECPrivateKeyParameters privateKeyParms =
new ECPrivateKeyParameters(new BigInteger(1, privateKey), domain);
ParametersWithRandom params = new ParametersWithRandom(privateKeyParms);
ecdsaSigner.init(true, params);
BigInteger[] sig = ecdsaSigner.generateSignature(data);
LinkedList<byte[]> sigData = new LinkedList<>();
byte[] publicKey = getPublicKey(privateKey);
byte recoveryId = getRecoveryId(sig[0].toByteArray(), sig[1].toByteArray(), data, publicKey);
for (BigInteger sigChunk : sig) {
sigData.add(sigChunk.toByteArray());
}
sigData.add(new byte[]{recoveryId});
return sigData.toArray(new byte[][]{});
} catch (Exception e) {
LOGGER.error(null, e);
return new byte[0][0];
}
}
示例15: verifySignature
import org.bouncycastle.crypto.signers.ECDSASigner; //导入方法依赖的package包/类
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);
}