com.google.bitcoin.bouncycastle.crypto.params.ECPrivateKeyParameters

Here are the examples of the java api class com.google.bitcoin.bouncycastle.crypto.params.ECPrivateKeyParameters taken from open source projects.

1. ECKey#sign()

Project: bitcoin-android
File: ECKey.java
/**
     * Calcuates an ECDSA signature in DER format for the given input hash. Note that the input is expected to be
     * 32 bytes long.
     */
public byte[] sign(byte[] input) {
    ECDSASigner signer = new ECDSASigner();
    ECPrivateKeyParameters privKey = new ECPrivateKeyParameters(priv, ecParams);
    signer.init(true, privKey);
    BigInteger[] sigs = signer.generateSignature(input);
    // components into a structure.
    try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        DERSequenceGenerator seq = new DERSequenceGenerator(bos);
        seq.addObject(new DERInteger(sigs[0]));
        seq.addObject(new DERInteger(sigs[1]));
        seq.close();
        return bos.toByteArray();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

2. ECMQVBasicAgreement#calculateAgreement()

Project: bitcoin-android
File: ECMQVBasicAgreement.java
public BigInteger calculateAgreement(CipherParameters pubKey) {
    MQVPublicParameters pubParams = (MQVPublicParameters) pubKey;
    ECPrivateKeyParameters staticPrivateKey = privParams.getStaticPrivateKey();
    ECPoint agreement = calculateMqvAgreement(staticPrivateKey.getParameters(), staticPrivateKey, privParams.getEphemeralPrivateKey(), privParams.getEphemeralPublicKey(), pubParams.getStaticPublicKey(), pubParams.getEphemeralPublicKey());
    return agreement.getX().toBigInteger();
}

3. ECNRSigner#generateSignature()

Project: bitcoin-android
File: ECNRSigner.java
// Section 7.2.5 ECSP-NR, pg 34
/**
     * generate a signature for the given message using the key we were
     * initialised with.  Generally, the order of the curve should be at 
     * least as long as the hash of the message of interest, and with 
     * ECNR it *must* be at least as long.  
     *
     * @param digest  the digest to be signed.
     * @exception DataLengthException if the digest is longer than the key allows
     */
public BigInteger[] generateSignature(byte[] digest) {
    if (!this.forSigning) {
        throw new IllegalStateException("not initialised for signing");
    }
    BigInteger n = ((ECPrivateKeyParameters) this.key).getParameters().getN();
    int nBitLength = n.bitLength();
    BigInteger e = new BigInteger(1, digest);
    int eBitLength = e.bitLength();
    ECPrivateKeyParameters privKey = (ECPrivateKeyParameters) key;
    if (eBitLength > nBitLength) {
        throw new DataLengthException("input too large for ECNR key.");
    }
    BigInteger r = null;
    BigInteger s = null;
    AsymmetricCipherKeyPair tempPair;
    do // generate r
    {
        // generate another, but very temporary, key pair using 
        // the same EC parameters
        ECKeyPairGenerator keyGen = new ECKeyPairGenerator();
        keyGen.init(new ECKeyGenerationParameters(privKey.getParameters(), this.random));
        tempPair = keyGen.generateKeyPair();
        //    BigInteger Vx = tempPair.getPublic().getW().getAffineX();
        // get temp's public key
        ECPublicKeyParameters V = (ECPublicKeyParameters) tempPair.getPublic();
        // get the point's x coordinate
        BigInteger Vx = V.getQ().getX().toBigInteger();
        r = Vx.add(e).mod(n);
    } while (r.equals(ECConstants.ZERO));
    // generate s
    // private key value
    BigInteger x = privKey.getD();
    // temp's private key value
    BigInteger u = ((ECPrivateKeyParameters) tempPair.getPrivate()).getD();
    s = u.subtract(r.multiply(x)).mod(n);
    BigInteger[] res = new BigInteger[2];
    res[0] = r;
    res[1] = s;
    return res;
}