Java 类org.bouncycastle.crypto.signers.HMacDSAKCalculator 实例源码

项目:fabric-api-archive    文件:BouncyCastleCrypto.java   
@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];
    }
}
项目:fabric-api    文件:BouncyCastleCrypto.java   
@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];
    }
}
项目:bop-bitcoin-client    文件:ECKeyPair.java   
@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;
}
项目:WalletCordova    文件:ECKeyPair.java   
@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;
}
项目:web3j    文件:ECKeyPair.java   
/**
 * 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();
}
项目:-deprecated-hlp-candidate    文件:PrivateKey.java   
/**
 * 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;
}
项目:fabric-java    文件:Crypto.java   
public BigInteger[] ecdsaSign(PrivateKey privateKey, ByteString message) {
    ECDSASigner signer = new ECDSASigner(new HMacDSAKCalculator(digest));
    ECPrivateKeyParameters ecdhPrivateKeyParameters;
    try {
        ecdhPrivateKeyParameters = (ECPrivateKeyParameters) (PrivateKeyFactory.createKey(privateKey.getEncoded()));
    } catch (IOException e) {
        logger.error("ECDSA sign load private key exception", e);
        throw new RuntimeException(e);
    }
    signer.init(true, ecdhPrivateKeyParameters);
    return signer.generateSignature(message.toByteArray());
}
项目:bushido-java-core    文件:ECKey.java   
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();
}
项目:blockio-java    文件:SigningUtils.java   
static String signData(String input, byte[] key) throws BlockIOException {
    ECDSASigner signer = new ECDSASigner(new HMacDSAKCalculator(new SHA256Digest()));
    X9ECParameters params = SECNamedCurves.getByName("secp256k1");
    ECDomainParameters ecParams = new ECDomainParameters(params.getCurve(), params.getG(), params.getN(), params.getH());
    BigInteger priv = new BigInteger(1, key);
    ECPrivateKeyParameters privKey = new ECPrivateKeyParameters(priv, ecParams);

    signer.init(true, privKey);
    BigInteger[] sigs = signer.generateSignature(fromHex(input));

    BigInteger r = sigs[0];
    BigInteger s = sigs[1];

    // BIP62: "S must be less than or equal to half of the Group Order N"
    BigInteger overTwo = params.getN().shiftRight(1);
    if (s.compareTo(overTwo) == 1) {
        s = params.getN().subtract(s);
    }

    try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        DERSequenceGenerator seq = new DERSequenceGenerator(bos);
        seq.addObject(new ASN1Integer(r));
        seq.addObject(new ASN1Integer(s));
        seq.close();
        return toHex(bos.toByteArray());
    } catch (IOException e) {
        throw new BlockIOException("That should never happen... File an issue report.");  // Cannot happen.
    }
}
项目:BitcoinCore    文件:ECKey.java   
/**
 * Creates a signature for the supplied contents using the private key
 *
 * @param       contents                Contents to be signed
 * @return                              ECDSA signature
 * @throws      ECException             Unable to create signature
 */
public ECDSASignature createSignature(byte[] contents) throws ECException {
    if (privKey == null)
        throw new IllegalStateException("No private key available");
    //
    // Get the double SHA-256 hash of the signed contents
    //
    byte[] contentsHash = Utils.doubleDigest(contents);
    //
    // Create the signature
    //
    BigInteger[] sigs;
    try {
        ECDSASigner signer = new ECDSASigner(new HMacDSAKCalculator(new SHA256Digest()));
        ECPrivateKeyParameters privKeyParams = new ECPrivateKeyParameters(privKey, ecParams);
        signer.init(true, privKeyParams);
        sigs = signer.generateSignature(contentsHash);
    } catch (RuntimeException exc) {
        throw new ECException("Exception while creating signature", exc);
    }
    //
    // Create a canonical signature by adjusting the S component to be less than or equal to
    // half the curve order.
    //
    if (sigs[1].compareTo(HALF_CURVE_ORDER) > 0)
        sigs[1] = ecParams.getN().subtract(sigs[1]);
    return new ECDSASignature(sigs[0], sigs[1]);
}
项目:gwt-crypto    文件:TlsECDSASigner.java   
protected DSA createDSAImpl(short hashAlgorithm)
{
    return new ECDSASigner(new HMacDSAKCalculator(TlsUtils.createHash(hashAlgorithm)));
}
项目:gwt-crypto    文件:TlsDSSSigner.java   
protected DSA createDSAImpl(short hashAlgorithm)
{
    return new DSASigner(new HMacDSAKCalculator(TlsUtils.createHash(hashAlgorithm)));
}
项目:gwt-crypto    文件:DeterministicDSATest.java   
private void doTestHMACDetDSASample(Digest digest, DSAPrivateKeyParameters privKey, BigInteger r, BigInteger s)
{
    doTestHMACDetECDSA(new DSASigner(new HMacDSAKCalculator(digest)), digest, SAMPLE, privKey, r, s);
}
项目:gwt-crypto    文件:DeterministicDSATest.java   
private void doTestHMACDetDSATest(Digest digest, DSAPrivateKeyParameters privKey, BigInteger r, BigInteger s)
{
    doTestHMACDetECDSA(new DSASigner(new HMacDSAKCalculator(digest)), digest, TEST, privKey, r, s);
}
项目:gwt-crypto    文件:DeterministicDSATest.java   
private void doTestHMACDetECDSASample(Digest digest, ECPrivateKeyParameters privKey, BigInteger r, BigInteger s)
{
    doTestHMACDetECDSA(new ECDSASigner(new HMacDSAKCalculator(digest)), digest, SAMPLE, privKey, r, s);
}
项目:gwt-crypto    文件:DeterministicDSATest.java   
private void doTestHMACDetECDSATest(Digest digest, ECPrivateKeyParameters privKey, BigInteger r, BigInteger s)
{
    doTestHMACDetECDSA(new ECDSASigner(new HMacDSAKCalculator(digest)), digest, TEST, privKey, r, s);
}
项目:Aki-SSL    文件:TlsECDSASigner.java   
protected DSA createDSAImpl(short hashAlgorithm)
{
    return new ECDSASigner(new HMacDSAKCalculator(TlsUtils.createHash(hashAlgorithm)));
}
项目:Aki-SSL    文件:TlsDSSSigner.java   
protected DSA createDSAImpl(short hashAlgorithm)
{
    return new DSASigner(new HMacDSAKCalculator(TlsUtils.createHash(hashAlgorithm)));
}
项目:Aki-SSL    文件:DSASigner.java   
public detDSA()
{
    super(new SHA1Digest(), new org.bouncycastle.crypto.signers.DSASigner(new HMacDSAKCalculator(new SHA1Digest())));
}
项目:Aki-SSL    文件:DSASigner.java   
public detDSA224()
{
    super(new SHA224Digest(), new org.bouncycastle.crypto.signers.DSASigner(new HMacDSAKCalculator(new SHA224Digest())));
}
项目:Aki-SSL    文件:DSASigner.java   
public detDSA256()
{
    super(new SHA256Digest(), new org.bouncycastle.crypto.signers.DSASigner(new HMacDSAKCalculator(new SHA256Digest())));
}
项目:Aki-SSL    文件:DSASigner.java   
public detDSA384()
{
    super(new SHA384Digest(), new org.bouncycastle.crypto.signers.DSASigner(new HMacDSAKCalculator(new SHA384Digest())));
}
项目:Aki-SSL    文件:DSASigner.java   
public detDSA512()
{
    super(new SHA512Digest(), new org.bouncycastle.crypto.signers.DSASigner(new HMacDSAKCalculator(new SHA512Digest())));
}
项目:Aki-SSL    文件:SignatureSpi.java   
public ecDetDSA()
{
    super(new SHA1Digest(), new ECDSASigner(new HMacDSAKCalculator(new SHA1Digest())), new StdDSAEncoder());
}
项目:Aki-SSL    文件:SignatureSpi.java   
public ecDetDSA224()
{
    super(new SHA224Digest(), new ECDSASigner(new HMacDSAKCalculator(new SHA224Digest())), new StdDSAEncoder());
}
项目:Aki-SSL    文件:SignatureSpi.java   
public ecDetDSA256()
{
    super(new SHA256Digest(), new ECDSASigner(new HMacDSAKCalculator(new SHA256Digest())), new StdDSAEncoder());
}
项目:Aki-SSL    文件:SignatureSpi.java   
public ecDetDSA384()
{
    super(new SHA384Digest(), new ECDSASigner(new HMacDSAKCalculator(new SHA384Digest())), new StdDSAEncoder());
}
项目:Aki-SSL    文件:SignatureSpi.java   
public ecDetDSA512()
{
    super(new SHA512Digest(), new ECDSASigner(new HMacDSAKCalculator(new SHA512Digest())), new StdDSAEncoder());
}
项目:TinyTravelTracker    文件:TlsECDSASigner.java   
protected DSA createDSAImpl(short hashAlgorithm)
{
    return new ECDSASigner(new HMacDSAKCalculator(TlsUtils.createHash(hashAlgorithm)));
}
项目:TinyTravelTracker    文件:TlsDSSSigner.java   
protected DSA createDSAImpl(short hashAlgorithm)
{
    return new DSASigner(new HMacDSAKCalculator(TlsUtils.createHash(hashAlgorithm)));
}
项目:CryptMeme    文件:DSASigner.java   
public detDSA()
{
    super(new SHA1Digest(), new org.bouncycastle.crypto.signers.DSASigner(new HMacDSAKCalculator(new SHA1Digest())));
}
项目:CryptMeme    文件:DSASigner.java   
public detDSA224()
{
    super(new SHA224Digest(), new org.bouncycastle.crypto.signers.DSASigner(new HMacDSAKCalculator(new SHA224Digest())));
}
项目:CryptMeme    文件:DSASigner.java   
public detDSA256()
{
    super(new SHA256Digest(), new org.bouncycastle.crypto.signers.DSASigner(new HMacDSAKCalculator(new SHA256Digest())));
}
项目:CryptMeme    文件:DSASigner.java   
public detDSA384()
{
    super(new SHA384Digest(), new org.bouncycastle.crypto.signers.DSASigner(new HMacDSAKCalculator(new SHA384Digest())));
}
项目:CryptMeme    文件:DSASigner.java   
public detDSA512()
{
    super(new SHA512Digest(), new org.bouncycastle.crypto.signers.DSASigner(new HMacDSAKCalculator(new SHA512Digest())));
}
项目:CryptMeme    文件:SignatureSpi.java   
public ecDetDSA()
{
    super(new SHA1Digest(), new ECDSASigner(new HMacDSAKCalculator(new SHA1Digest())), new StdDSAEncoder());
}
项目:CryptMeme    文件:SignatureSpi.java   
public ecDetDSA224()
{
    super(new SHA224Digest(), new ECDSASigner(new HMacDSAKCalculator(new SHA224Digest())), new StdDSAEncoder());
}
项目:CryptMeme    文件:SignatureSpi.java   
public ecDetDSA256()
{
    super(new SHA256Digest(), new ECDSASigner(new HMacDSAKCalculator(new SHA256Digest())), new StdDSAEncoder());
}
项目:CryptMeme    文件:SignatureSpi.java   
public ecDetDSA384()
{
    super(new SHA384Digest(), new ECDSASigner(new HMacDSAKCalculator(new SHA384Digest())), new StdDSAEncoder());
}
项目:CryptMeme    文件:SignatureSpi.java   
public ecDetDSA512()
{
    super(new SHA512Digest(), new ECDSASigner(new HMacDSAKCalculator(new SHA512Digest())), new StdDSAEncoder());
}