本文整理汇总了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];
}
}
示例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;
}
示例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();
}
示例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;
}
示例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());
}
示例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();
}
示例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.
}
}
示例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]);
}
示例9: createDSAImpl
import org.bouncycastle.crypto.signers.HMacDSAKCalculator; //导入依赖的package包/类
protected DSA createDSAImpl(short hashAlgorithm)
{
return new ECDSASigner(new HMacDSAKCalculator(TlsUtils.createHash(hashAlgorithm)));
}
示例10: createDSAImpl
import org.bouncycastle.crypto.signers.HMacDSAKCalculator; //导入依赖的package包/类
protected DSA createDSAImpl(short hashAlgorithm)
{
return new DSASigner(new HMacDSAKCalculator(TlsUtils.createHash(hashAlgorithm)));
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例15: detDSA
import org.bouncycastle.crypto.signers.HMacDSAKCalculator; //导入依赖的package包/类
public detDSA()
{
super(new SHA1Digest(), new org.bouncycastle.crypto.signers.DSASigner(new HMacDSAKCalculator(new SHA1Digest())));
}