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


Java HMacDSAKCalculator类代码示例

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


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

示例1: doSign

import org.spongycastle.crypto.signers.HMacDSAKCalculator; //导入依赖的package包/类
/**
 * Signs the given hash and returns the R and S components as BigIntegers
 * and put them in ECDSASignature
 *
 * @param input to sign
 * @return ECDSASignature signature that contains the R and S components
 */
public ECDSASignature doSign(byte[] input) {
    if (input.length != 32) {
        throw new IllegalArgumentException("Expected 32 byte input to ECDSA signature, not " + input.length);
    }
    // No decryption of private key required.
    if (privKey == null)
        throw new MissingPrivateKeyException();
    if (privKey instanceof BCECPrivateKey) {
        ECDSASigner signer = new ECDSASigner(new HMacDSAKCalculator(new SHA256Digest()));
        ECPrivateKeyParameters privKeyParams = new ECPrivateKeyParameters(((BCECPrivateKey) privKey).getD(), CURVE);
        signer.init(true, privKeyParams);
        BigInteger[] components = signer.generateSignature(input);
        return new ECDSASignature(components[0], components[1]).toCanonicalised();
    } else {
        try {
            final Signature ecSig = ECSignatureFactory.getRawInstance(provider);
            ecSig.initSign(privKey);
            ecSig.update(input);
            final byte[] derSignature = ecSig.sign();
            return ECDSASignature.decodeFromDER(derSignature).toCanonicalised();
        } catch (SignatureException | InvalidKeyException ex) {
            throw new RuntimeException("ECKey signing error", ex);
        }
    }
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:33,代码来源:ECKey.java

示例2: doSign

import org.spongycastle.crypto.signers.HMacDSAKCalculator; //导入依赖的package包/类
protected ECDSASignature doSign(Sha256Hash input, BigInteger privateKeyForSigning) {
    if (Secp256k1Context.isEnabled()) {
        try {
            byte[] signature = NativeSecp256k1.sign(
                    input.getBytes(),
                    Utils.bigIntegerToBytes(privateKeyForSigning, 32)
            );
            return ECDSASignature.decodeFromDER(signature);
        } catch (NativeSecp256k1Util.AssertFailException e) {
            log.error("Caught AssertFailException inside secp256k1", e);
            throw new RuntimeException(e);
        }
    }
    if (FAKE_SIGNATURES)
        return TransactionSignature.dummy();
    checkNotNull(privateKeyForSigning);
    ECDSASigner signer = new ECDSASigner(new HMacDSAKCalculator(new SHA256Digest()));
    ECPrivateKeyParameters privKey = new ECPrivateKeyParameters(privateKeyForSigning, CURVE);
    signer.init(true, privKey);
    BigInteger[] components = signer.generateSignature(input.getBytes());
    return new ECDSASignature(components[0], components[1]).toCanonicalised();
}
 
开发者ID:creativechain,项目名称:creacoinj,代码行数:23,代码来源:ECKey.java

示例3: doSign

import org.spongycastle.crypto.signers.HMacDSAKCalculator; //导入依赖的package包/类
protected ECDSASignature doSign(Sha256Hash input, BigInteger privateKeyForSigning) {
    if (Secp256k1Context.isEnabled()) {
        try {
            byte[] signature = NativeSecp256k1.sign(input.getBytes(),
                    CryptoUtils.bigIntegerToBytes(privateKeyForSigning, 32));
            return ECDSASignature.decodeFromDER(signature);
        } catch (NativeSecp256k1Util.AssertFailException e) {
            log.error("Caught AssertFailException inside secp256k1", e);
            throw new RuntimeException(e);
        }
    }
    if (FAKE_SIGNATURES)
        // return TransactionSignature.dummy();
        checkNotNull(privateKeyForSigning);
    ECDSASigner signer = new ECDSASigner(new HMacDSAKCalculator(new SHA256Digest()));
    ECPrivateKeyParameters privKey = new ECPrivateKeyParameters(privateKeyForSigning, CURVE);
    signer.init(true, privKey);
    BigInteger[] components = signer.generateSignature(input.getBytes());
    return new ECDSASignature(components[0], components[1]).toCanonicalised();
}
 
开发者ID:marvin-we,项目名称:crypto-core,代码行数:21,代码来源:ECKey.java

示例4: doSign

import org.spongycastle.crypto.signers.HMacDSAKCalculator; //导入依赖的package包/类
protected ECDSASignature doSign(Sha256Hash input, BigInteger privateKeyForSigning) {
    Utils.checkNotNull(privateKeyForSigning);
    ECDSASigner signer = new ECDSASigner(new HMacDSAKCalculator(new SHA256Digest()));
    ECPrivateKeyParameters privKey = new ECPrivateKeyParameters(privateKeyForSigning, CURVE);
    signer.init(true, privKey);
    BigInteger[] components = signer.generateSignature(input.getBytes());
    return new ECDSASignature(components[0], components[1]).toCanonicalised();
}
 
开发者ID:nuls-io,项目名称:nuls,代码行数:9,代码来源:ECKey.java

示例5: doSign

import org.spongycastle.crypto.signers.HMacDSAKCalculator; //导入依赖的package包/类
/**
 * Signs the given hash and returns the R and S components as BigIntegers
 * and put them in ECDSASignature
 *
 * @param input to sign
 * @return ECDSASignature signature that contains the R and S components
 */
public ECDSASignature doSign(byte[] input) {
    // No decryption of private key required.
    if (priv == null) {
        throw new MissingPrivateKeyException();
    }
    ECDSASigner signer = new ECDSASigner(new HMacDSAKCalculator(new SHA256Digest()));
    ECPrivateKeyParameters privKey = new ECPrivateKeyParameters(priv, CURVE);
    signer.init(true, privKey);
    BigInteger[] components = signer.generateSignature(input);
    return new ECDSASignature(components[0], components[1]).toCanonicalised();
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:19,代码来源:ECKey.java

示例6: doSign

import org.spongycastle.crypto.signers.HMacDSAKCalculator; //导入依赖的package包/类
/**
 * Signs the given hash and returns the R and S components as BigIntegers
 * and put them in ECDSASignature
 *
 * @param input to sign
 * @return ECDSASignature signature that contains the R and S components
 */
public ECDSASignature doSign(byte[] input) {
  if (input.length != 32) {
    throw new IllegalArgumentException(
        "Expected 32 byte input to ECDSA signature, not " + input.length);
  }
  // No decryption of private key required.
  if (privKey == null) throw new MissingPrivateKeyException();
  if (privKey instanceof BCECPrivateKey) {
    ECDSASigner signer = new ECDSASigner(new HMacDSAKCalculator(new SHA256Digest()));
    ECPrivateKeyParameters privKeyParams =
        new ECPrivateKeyParameters(((BCECPrivateKey) privKey).getD(), CURVE);
    signer.init(true, privKeyParams);
    BigInteger[] components = signer.generateSignature(input);
    return new ECDSASignature(components[0], components[1]).toCanonicalised();
  } else {
    try {
      Signature ecSig = ECSignatureFactory.getRawInstance(provider);
      ecSig.initSign(privKey);
      ecSig.update(input);
      byte[] derSignature = ecSig.sign();
      return ECDSASignature.decodeFromDER(derSignature)
          .toCanonicalised();
    } catch (SignatureException | InvalidKeyException ex) {
      throw new RuntimeException("ECKey signing error", ex);
    }
  }
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:35,代码来源:ECKey.java

示例7: doSign

import org.spongycastle.crypto.signers.HMacDSAKCalculator; //导入依赖的package包/类
protected ECDSASignature doSign(Sha256Hash input, BigInteger privateKeyForSigning) {
    if (FAKE_SIGNATURES)
        return TransactionSignature.dummy();
    checkNotNull(privateKeyForSigning);
    ECDSASigner signer = new ECDSASigner(new HMacDSAKCalculator(new SHA256Digest()));
    ECPrivateKeyParameters privKey = new ECPrivateKeyParameters(privateKeyForSigning, CURVE);
    signer.init(true, privKey);
    BigInteger[] components = signer.generateSignature(input.getBytes());
    return new ECDSASignature(components[0], components[1]).toCanonicalised();
}
 
开发者ID:rsksmart,项目名称:bitcoinj-thin,代码行数:11,代码来源:BtcECKey.java

示例8: doSign

import org.spongycastle.crypto.signers.HMacDSAKCalculator; //导入依赖的package包/类
/**
 * Signs the given hash and returns the R and S components as BigIntegers and put them in
 * ECDSASignature
 *
 * @param input
 *            to sign
 * @return ECDSASignature signature that contains the R and S components
 */
public ECDSASignature doSign(byte[] input) {
    // No decryption of private key required.
    if (priv == null)
        throw new MissingPrivateKeyException();
    ECDSASigner signer = new ECDSASigner(new HMacDSAKCalculator(new SHA256Digest()));
    ECPrivateKeyParameters privKey = new ECPrivateKeyParameters(priv, CURVE);
    signer.init(true, privKey);
    BigInteger[] components = signer.generateSignature(input);
    return new ECDSASignature(components[0], components[1]).toCanonicalised();
}
 
开发者ID:cegeka,项目名称:tether,代码行数:19,代码来源:ECKey.java

示例9: sign

import org.spongycastle.crypto.signers.HMacDSAKCalculator; //导入依赖的package包/类
public ECDSASignature sign(byte[] input) {
    ECDSASigner signer = new ECDSASigner(new HMacDSAKCalculator(new SHA256Digest()));
    ECPrivateKeyParameters privKey = new ECPrivateKeyParameters(priv, CURVE);
    signer.init(true, privKey);
    BigInteger[] components = signer.generateSignature(input);
    final ECDSASignature signature = new ECDSASignature(components[0], components[1]);
    signature.ensureCanonical();
    return signature;
}
 
开发者ID:chaincloud-dot-com,项目名称:chaincloud-v,代码行数:10,代码来源:ECKey.java

示例10: sign

import org.spongycastle.crypto.signers.HMacDSAKCalculator; //导入依赖的package包/类
/**
 * Signs the given hash and returns the R and S components as BigIntegers. In the Bitcoin protocol, they are
 * usually encoded using DER format, so you want {@link net.bither.bitherj.crypto.ECKey.ECDSASignature#encodeToDER()}
 * instead. However sometimes the independent components can be useful, for instance, if you're doing to do further
 * EC maths on them.
 *
 * @param aesKey The AES key to use for decryption of the private key. If null then no decryption is required.
 * @throws net.bither.bitherj.crypto.KeyCrypterException if this ECKey doesn't have a private part.
 */
public ECDSASignature sign(byte[] input, @Nullable KeyParameter aesKey) throws KeyCrypterException {
    if (FAKE_SIGNATURES)
        return TransactionSignature.dummy();

    // The private key bytes to use for signing.
    BigInteger privateKeyForSigning;

    if (isEncrypted()) {
        // The private key needs decrypting before use.
        if (aesKey == null) {
            throw new KeyCrypterException("This ECKey is encrypted but no decryption key has been supplied.");
        }

        if (keyCrypter == null) {
            throw new KeyCrypterException("There is no KeyCrypter to decrypt the private key for signing.");
        }

        privateKeyForSigning = new BigInteger(1, keyCrypter.decrypt(encryptedPrivateKey, aesKey));
        // Check encryption was correct.
        if (!Arrays.equals(pub, publicKeyFromPrivate(privateKeyForSigning, isCompressed())))
            throw new KeyCrypterException("Could not decrypt bytes");
    } else {
        // No decryption of private key required.
        if (priv == null) {
            throw new KeyCrypterException("This ECKey does not have the private key necessary for signing.");
        } else {
            privateKeyForSigning = priv;
        }
    }

    ECDSASigner signer = new ECDSASigner(new HMacDSAKCalculator(new SHA256Digest()));
    ECPrivateKeyParameters privKey = new ECPrivateKeyParameters(privateKeyForSigning, CURVE);
    signer.init(true, privKey);
    BigInteger[] components = signer.generateSignature(input);
    final ECDSASignature signature = new ECDSASignature(components[0], components[1]);
    signature.ensureCanonical();
    return signature;
}
 
开发者ID:bither,项目名称:bitherj,代码行数:48,代码来源:ECKey.java

示例11: doSign

import org.spongycastle.crypto.signers.HMacDSAKCalculator; //导入依赖的package包/类
/**
 * Signs the given hash and returns the R and S components as BigIntegers 
 * and put them in ECDSASignature 
 * 
 * @param input to sign
 * @return ECDSASignature signature that contains the R and S components
 */
public ECDSASignature doSign(byte[] input) {
    // No decryption of private key required.
    if (priv == null)
        throw new MissingPrivateKeyException();
    check(priv != null, "Private key must not be null");
    ECDSASigner signer = new ECDSASigner(new HMacDSAKCalculator(new SHA256Digest()));
    ECPrivateKeyParameters privKey = new ECPrivateKeyParameters(priv, CURVE);
    signer.init(true, privKey);
    BigInteger[] components = signer.generateSignature(input);
    return new ECDSASignature(components[0], components[1]).toCanonicalised();
}
 
开发者ID:ethereumj,项目名称:ethereumj,代码行数:19,代码来源:ECKey.java

示例12: sign

import org.spongycastle.crypto.signers.HMacDSAKCalculator; //导入依赖的package包/类
/**
 * Signs the given hash and returns the R and S components as BigIntegers. In the Bitcoin protocol, they are
 * usually encoded using DER format, so you want {@link com.google.dogecoin.core.ECKey.ECDSASignature#encodeToDER()}
 * instead. However sometimes the independent components can be useful, for instance, if you're doing to do further
 * EC maths on them.
 *
 * @param aesKey The AES key to use for decryption of the private key. If null then no decryption is required.
 * @throws KeyCrypterException if this ECKey doesn't have a private part.
 */
public ECDSASignature sign(Sha256Hash input, @Nullable KeyParameter aesKey) throws KeyCrypterException {
    if (FAKE_SIGNATURES)
        return TransactionSignature.dummy();

    // The private key bytes to use for signing.
    BigInteger privateKeyForSigning;

    if (isEncrypted()) {
        // The private key needs decrypting before use.
        if (aesKey == null) {
            throw new KeyCrypterException("This ECKey is encrypted but no decryption key has been supplied.");
        }

        if (keyCrypter == null) {
            throw new KeyCrypterException("There is no KeyCrypter to decrypt the private key for signing.");
        }

        privateKeyForSigning = new BigInteger(1, keyCrypter.decrypt(encryptedPrivateKey, aesKey));
        // Check encryption was correct.
        if (!Arrays.equals(pub, publicKeyFromPrivate(privateKeyForSigning, isCompressed())))
            throw new KeyCrypterException("Could not decrypt bytes");
    } else {
        // No decryption of private key required.
        if (priv == null) {
            throw new KeyCrypterException("This ECKey does not have the private key necessary for signing.");
        } else {
            privateKeyForSigning = priv;
        }
    }

    ECDSASigner signer = new ECDSASigner(new HMacDSAKCalculator(new SHA256Digest()));
    ECPrivateKeyParameters privKey = new ECPrivateKeyParameters(privateKeyForSigning, CURVE);
    signer.init(true, privKey);
    BigInteger[] components = signer.generateSignature(input.getBytes());
    return new ECDSASignature(components[0], components[1]).toCanonicalised();
}
 
开发者ID:pavel4n,项目名称:wowdoge.org,代码行数:46,代码来源:ECKey.java

示例13: sign

import org.spongycastle.crypto.signers.HMacDSAKCalculator; //导入依赖的package包/类
/**
 * Signs the given hash and returns the R and S components as BigIntegers. In the Bitcoin protocol, they are
 * usually encoded using DER format, so you want {@link com.google.bitcoin.core.ECKey.ECDSASignature#encodeToDER()}
 * instead. However sometimes the independent components can be useful, for instance, if you're doing to do further
 * EC maths on them.
 *
 * @param aesKey The AES key to use for decryption of the private key. If null then no decryption is required.
 * @throws KeyCrypterException if this ECKey doesn't have a private part.
 */
public ECDSASignature sign(Sha256Hash input, @Nullable KeyParameter aesKey) throws KeyCrypterException {
    if (FAKE_SIGNATURES)
        return TransactionSignature.dummy();

    // The private key bytes to use for signing.
    BigInteger privateKeyForSigning;

    if (isEncrypted()) {
        // The private key needs decrypting before use.
        if (aesKey == null) {
            throw new KeyCrypterException("This ECKey is encrypted but no decryption key has been supplied.");
        }

        if (keyCrypter == null) {
            throw new KeyCrypterException("There is no KeyCrypter to decrypt the private key for signing.");
        }

        privateKeyForSigning = new BigInteger(1, keyCrypter.decrypt(encryptedPrivateKey, aesKey));
        // Check encryption was correct.
        if (!Arrays.equals(pub, publicKeyFromPrivate(privateKeyForSigning, isCompressed())))
            throw new KeyCrypterException("Could not decrypt bytes");
    } else {
        // No decryption of private key required.
        if (priv == null) {
            throw new KeyCrypterException("This ECKey does not have the private key necessary for signing.");
        } else {
            privateKeyForSigning = priv;
        }
    }

    ECDSASigner signer = new ECDSASigner(new HMacDSAKCalculator(new SHA256Digest()));
    ECPrivateKeyParameters privKey = new ECPrivateKeyParameters(privateKeyForSigning, CURVE);
    signer.init(true, privKey);
    BigInteger[] components = signer.generateSignature(input.getBytes());
    return new ECDSASignature(components[0], components[1]).toCanonicalised();
}
 
开发者ID:HashEngineering,项目名称:quarkcoinj,代码行数:46,代码来源:ECKey.java

示例14: SignatureImpl

import org.spongycastle.crypto.signers.HMacDSAKCalculator; //导入依赖的package包/类
SignatureImpl(SecureRandom secureRandom) {
	this.secureRandom = secureRandom;
	Digest digest = new Blake2sDigest();
	DSAKCalculator calculator = new HMacDSAKCalculator(digest);
	signer = new DSADigestSigner(new ECDSASigner(calculator), digest);
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:7,代码来源:SignatureImpl.java

示例15: SignatureImpl

import org.spongycastle.crypto.signers.HMacDSAKCalculator; //导入依赖的package包/类
SignatureImpl(SecureRandom secureRandom) {
	this.secureRandom = secureRandom;
	Digest digest = new SHA384Digest();
	DSAKCalculator calculator = new HMacDSAKCalculator(digest);
	signer = new DSADigestSigner(new ECDSASigner(calculator), digest);
}
 
开发者ID:kiggundu,项目名称:briar,代码行数:7,代码来源:SignatureImpl.java


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