当前位置: 首页>>代码示例>>Java>>正文


Java HMacDSAKCalculator类代码示例

本文整理汇总了Java中org.bouncycastle.crypto.signers.HMacDSAKCalculator的典型用法代码示例。如果您正苦于以下问题:Java HMacDSAKCalculator类的具体用法?Java HMacDSAKCalculator怎么用?Java HMacDSAKCalculator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HMacDSAKCalculator类属于org.bouncycastle.crypto.signers包,在下文中一共展示了HMacDSAKCalculator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sign

import org.bouncycastle.crypto.signers.HMacDSAKCalculator; //导入依赖的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];
    }
}
 
开发者ID:hyperledger-archives,项目名称:fabric-api-archive,代码行数:17,代码来源:BouncyCastleCrypto.java

示例2: sign

import org.bouncycastle.crypto.signers.HMacDSAKCalculator; //导入依赖的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;
}
 
开发者ID:bitsofproof,项目名称:bop-bitcoin-client,代码行数:25,代码来源:ECKeyPair.java

示例3: sign

import org.bouncycastle.crypto.signers.HMacDSAKCalculator; //导入依赖的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();
}
 
开发者ID:web3j,项目名称:web3j,代码行数:15,代码来源:ECKeyPair.java

示例4: sign

import org.bouncycastle.crypto.signers.HMacDSAKCalculator; //导入依赖的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;
}
 
开发者ID:DigitalAssetCom,项目名称:-deprecated-hlp-candidate,代码行数:22,代码来源:PrivateKey.java

示例5: ecdsaSign

import org.bouncycastle.crypto.signers.HMacDSAKCalculator; //导入依赖的package包/类
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());
}
 
开发者ID:GrapeBaBa,项目名称:fabric-java,代码行数:13,代码来源:Crypto.java

示例6: sign

import org.bouncycastle.crypto.signers.HMacDSAKCalculator; //导入依赖的package包/类
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();
}
 
开发者ID:bushidowallet,项目名称:bushido-java-core,代码行数:16,代码来源:ECKey.java

示例7: signData

import org.bouncycastle.crypto.signers.HMacDSAKCalculator; //导入依赖的package包/类
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.
    }
}
 
开发者ID:langerhans,项目名称:blockio-java,代码行数:31,代码来源:SigningUtils.java

示例8: createSignature

import org.bouncycastle.crypto.signers.HMacDSAKCalculator; //导入依赖的package包/类
/**
 * 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]);
}
 
开发者ID:ScripterRon,项目名称:BitcoinCore,代码行数:35,代码来源:ECKey.java

示例9: createDSAImpl

import org.bouncycastle.crypto.signers.HMacDSAKCalculator; //导入依赖的package包/类
protected DSA createDSAImpl(short hashAlgorithm)
{
    return new ECDSASigner(new HMacDSAKCalculator(TlsUtils.createHash(hashAlgorithm)));
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:5,代码来源:TlsECDSASigner.java

示例10: createDSAImpl

import org.bouncycastle.crypto.signers.HMacDSAKCalculator; //导入依赖的package包/类
protected DSA createDSAImpl(short hashAlgorithm)
{
    return new DSASigner(new HMacDSAKCalculator(TlsUtils.createHash(hashAlgorithm)));
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:5,代码来源:TlsDSSSigner.java

示例11: doTestHMACDetDSASample

import org.bouncycastle.crypto.signers.HMacDSAKCalculator; //导入依赖的package包/类
private void doTestHMACDetDSASample(Digest digest, DSAPrivateKeyParameters privKey, BigInteger r, BigInteger s)
{
    doTestHMACDetECDSA(new DSASigner(new HMacDSAKCalculator(digest)), digest, SAMPLE, privKey, r, s);
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:5,代码来源:DeterministicDSATest.java

示例12: doTestHMACDetDSATest

import org.bouncycastle.crypto.signers.HMacDSAKCalculator; //导入依赖的package包/类
private void doTestHMACDetDSATest(Digest digest, DSAPrivateKeyParameters privKey, BigInteger r, BigInteger s)
{
    doTestHMACDetECDSA(new DSASigner(new HMacDSAKCalculator(digest)), digest, TEST, privKey, r, s);
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:5,代码来源:DeterministicDSATest.java

示例13: doTestHMACDetECDSASample

import org.bouncycastle.crypto.signers.HMacDSAKCalculator; //导入依赖的package包/类
private void doTestHMACDetECDSASample(Digest digest, ECPrivateKeyParameters privKey, BigInteger r, BigInteger s)
{
    doTestHMACDetECDSA(new ECDSASigner(new HMacDSAKCalculator(digest)), digest, SAMPLE, privKey, r, s);
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:5,代码来源:DeterministicDSATest.java

示例14: doTestHMACDetECDSATest

import org.bouncycastle.crypto.signers.HMacDSAKCalculator; //导入依赖的package包/类
private void doTestHMACDetECDSATest(Digest digest, ECPrivateKeyParameters privKey, BigInteger r, BigInteger s)
{
    doTestHMACDetECDSA(new ECDSASigner(new HMacDSAKCalculator(digest)), digest, TEST, privKey, r, s);
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:5,代码来源:DeterministicDSATest.java

示例15: detDSA

import org.bouncycastle.crypto.signers.HMacDSAKCalculator; //导入依赖的package包/类
public detDSA()
{
    super(new SHA1Digest(), new org.bouncycastle.crypto.signers.DSASigner(new HMacDSAKCalculator(new SHA1Digest())));
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:5,代码来源:DSASigner.java


注:本文中的org.bouncycastle.crypto.signers.HMacDSAKCalculator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。