org.bouncycastle.crypto.params.ECPrivateKeyParameters.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(11.4k)|赞(0)|评价(0)|浏览(1191)

本文整理了Java中org.bouncycastle.crypto.params.ECPrivateKeyParameters.<init>()方法的一些代码示例,展示了ECPrivateKeyParameters.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ECPrivateKeyParameters.<init>()方法的具体详情如下:
包路径:org.bouncycastle.crypto.params.ECPrivateKeyParameters
类名称:ECPrivateKeyParameters
方法名:<init>

ECPrivateKeyParameters.<init>介绍

暂无

代码示例

代码示例来源:origin: web3j/web3j

/**
 * 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();
}

代码示例来源:origin: ZZMarquis/gmhelper

public static ECPrivateKeyParameters createECPrivateKeyParameters(BigInteger d,
  ECDomainParameters domainParameters) {
  return new ECPrivateKeyParameters(d, domainParameters);
}

代码示例来源:origin: NemProject/nem.core

/**
 * Gets the EC private key parameters.
 *
 * @param privateKey The private key.
 * @return The EC private key parameters.
 */
public static ECPrivateKeyParameters getPrivateKeyParameters(final PrivateKey privateKey) {
  return new ECPrivateKeyParameters(privateKey.getRaw(), SecP256K1Curve.secp256k1().getParams());
}

代码示例来源:origin: radixdlt/radixdlt-java

public ECSignature sign(byte[] data) {
  ECDomainParameters domain = ECKeyPairGenerator.getDomain((getPublicKey().length() - 1) * 8);
  ECDSASigner signer = new ECDSASigner();
  signer.init(true, new ECPrivateKeyParameters(new BigInteger(1, getPrivateKey()), domain));
  BigInteger[] components = signer.generateSignature(data);
  ECSignature signature = new ECSignature(components[0], components[1]);
  return signature;
}

代码示例来源:origin: hyperledger-archives/fabric-api

@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];
  }
}

代码示例来源:origin: com.bushidowallet/bushido-core-lib

public byte[] sign(byte[] message) throws Exception
{
  if (priv == null) {
    throw new Exception("Unable to sign");
  }
  ECDSASigner signer = new ECDSASigner(new HMacDSAKCalculator(new SHA256Digest()));
  signer.init(true, new ECPrivateKeyParameters(priv, params));
  BigInteger[] signature = signer.generateSignature(message);
  ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  DERSequenceGenerator seqGen = new DERSequenceGenerator(outputStream);
  seqGen.addObject(new ASN1Integer(signature[0]));
  seqGen.addObject(new ASN1Integer(signature[1]));
  seqGen.close();
  return outputStream.toByteArray();
}

代码示例来源:origin: ZZMarquis/gmhelper

public static ECPrivateKeyParameters convertPrivateKeyToParameters(BCECPrivateKey ecPriKey) {
  ECParameterSpec parameterSpec = ecPriKey.getParameters();
  ECDomainParameters domainParameters = new ECDomainParameters(parameterSpec.getCurve(), parameterSpec.getG(),
    parameterSpec.getN(), parameterSpec.getH());
  return new ECPrivateKeyParameters(ecPriKey.getD(), domainParameters);
}

代码示例来源:origin: CryptoKass/dilithium

public BigInteger keyAgreement(ECPoint otherParty) {
  if (privKey == null) {
    throw new MissingPrivateKeyException();
  } else if (privKey instanceof BCECPrivateKey) {
    final ECDHBasicAgreement agreement = new ECDHBasicAgreement();
    agreement.init(new ECPrivateKeyParameters(((BCECPrivateKey) privKey).getD(), CURVE));
    return agreement.calculateAgreement(new ECPublicKeyParameters(otherParty, CURVE));
  } else {
    try {
      final KeyAgreement agreement = ECKeyAgreement.getInstance(this.provider);
      agreement.init(this.privKey);
      agreement.doPhase(
          ECKeyFactory.getInstance(this.provider)
              .generatePublic(new ECPublicKeySpec(otherParty, CURVE_SPEC)),
          /* lastPhase */ true);
      return new BigInteger(1, agreement.generateSecret());
    } catch (IllegalStateException | InvalidKeyException | InvalidKeySpecException ex) {
      throw new RuntimeException("ECDH key agreement failure", ex);
    }
  }
}

代码示例来源:origin: neow3j/neow3j

/**
 * Sign a hash with the private key of this key pair.
 *
 * @param transactionHash the hash to sign
 * @return A raw {@link BigInteger} array with the signature
 */
public BigInteger[] sign(byte[] transactionHash) {
  ECDSASigner signer = new ECDSASigner(new HMacDSAKCalculator(new SHA256Digest()));
  ECPrivateKeyParameters privKey = new ECPrivateKeyParameters(privateKey, NeoConstants.CURVE);
  signer.init(true, privKey);
  return signer.generateSignature(transactionHash);
}

代码示例来源:origin: eBay/UAF

/**
 * 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;
}

代码示例来源:origin: org.web3j/crypto

/**
 * 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();
}

代码示例来源:origin: com.cryptape.cita/crypto

/**
 * 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();
}

代码示例来源:origin: eBay/UAF

/**
 * 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;
}

代码示例来源:origin: io.github.moacchain/crypto

/**
 * 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();
}

代码示例来源:origin: io.daonomic.scalether/util

private static ECDSASignature sign(byte[] transactionHash, BigInteger privateKey) {
  ECDSASigner signer = new ECDSASigner(new HMacDSAKCalculator(new SHA256Digest()));
  ECPrivateKeyParameters privKey = new ECPrivateKeyParameters(privateKey, CURVE);
  signer.init(true, privKey);
  BigInteger[] components = signer.generateSignature(transactionHash);
  return new ECDSASignature(components[0], components[1]).toCanonicalised();
}

代码示例来源:origin: org.nervos/crypto

/**
 * 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();
}

代码示例来源:origin: org.medibloc.panacea/crypto

/**
 * 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(this.privKey, Keys.CURVE);
  signer.init(true, privKey);
  BigInteger[] components = signer.generateSignature(transactionHash);
  return new ECDSASignature(components[0], components[1]).toCanonicalised();
}

代码示例来源:origin: FISCO-BCOS/web3sdk

public static ECDSASignature sign(byte[] transactionHash, BigInteger privateKey) {
  ECDSASigner signer = new ECDSASigner(new HMacDSAKCalculator(new SHA256Digest()));
  ECPrivateKeyParameters privKey = new ECPrivateKeyParameters(privateKey, CURVE);
  signer.init(true, privKey);
  BigInteger[] components = signer.generateSignature(transactionHash);
  return new ECDSASignature(components[0], components[1]).toCanonicalised();
}

代码示例来源:origin: NemProject/nem.core

@Override
public Signature sign(final byte[] data) {
  if (!this.keyPair.hasPrivateKey()) {
    throw new CryptoException("cannot sign without private key");
  }
  final ECDSASigner signer = this.createECDSASigner();
  final ECPrivateKeyParameters privateKeyParameters = new ECPrivateKeyParameters(
      this.keyPair.getPrivateKey().getRaw(),
      SecP256K1Curve.secp256k1().getParams());
  signer.init(true, privateKeyParameters);
  final byte[] hash = Hashes.sha3_256(data);
  final BigInteger[] components = signer.generateSignature(hash);
  final Signature signature = new Signature(components[0], components[1]);
  return this.makeSignatureCanonical(signature);
}

代码示例来源:origin: org.cryptacular/cryptacular

/**
  * Parses an EC private key as defined in RFC 5915.
  * <pre>
  *      ECPrivateKey ::= SEQUENCE {
  *        version        INTEGER { ecPrivkeyVer1(1) } (ecPrivkeyVer1),
  *        privateKey     OCTET STRING,
  *        parameters [0] ECParameters {{ NamedCurve }} OPTIONAL,
  *        publicKey  [1] BIT STRING OPTIONAL
  *      }
  * </pre>
  *
  * @param  seq  ASN1 sequence to parse
  *
  * @return  EC private key
  */
 private ECPrivateKeyParameters parseECPrivateKey(final ASN1Sequence seq)
 {
  final ASN1TaggedObject asn1Params = ASN1TaggedObject.getInstance(seq.getObjectAt(2));
  final X9ECParameters params;
  if (asn1Params.getObject() instanceof ASN1ObjectIdentifier) {
   params = ECUtil.getNamedCurveByOid(ASN1ObjectIdentifier.getInstance(asn1Params.getObject()));
  } else {
   params = X9ECParameters.getInstance(asn1Params.getObject());
  }
  return new ECPrivateKeyParameters(
   new BigInteger(1, ASN1OctetString.getInstance(seq.getObjectAt(1)).getOctets()),
   new ECDomainParameters(params.getCurve(), params.getG(), params.getN(), params.getH(), params.getSeed()));
 }
}

相关文章

微信公众号

最新文章

更多