本文整理匯總了Java中org.bouncycastle.crypto.Digest類的典型用法代碼示例。如果您正苦於以下問題:Java Digest類的具體用法?Java Digest怎麽用?Java Digest使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Digest類屬於org.bouncycastle.crypto包,在下文中一共展示了Digest類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createHash
import org.bouncycastle.crypto.Digest; //導入依賴的package包/類
public static final Digest createHash(int hashAlgorithm)
{
switch (hashAlgorithm)
{
case HashAlgorithm.md5:
return new MD5Digest();
case HashAlgorithm.sha1:
return new SHA1Digest();
case HashAlgorithm.sha224:
return new SHA224Digest();
case HashAlgorithm.sha256:
return new SHA256Digest();
case HashAlgorithm.sha384:
return new SHA384Digest();
case HashAlgorithm.sha512:
return new SHA512Digest();
default:
throw new IllegalArgumentException("unknown HashAlgorithm");
}
}
示例2: calculateKeyId
import org.bouncycastle.crypto.Digest; //導入依賴的package包/類
static byte[] calculateKeyId(SubjectPublicKeyInfo info)
{
Digest dig = new SHA1Digest(); // TODO: include definition of SHA-1 here
byte[] hash = new byte[dig.getDigestSize()];
byte[] spkiEnc = new byte[0];
try
{
spkiEnc = info.getEncoded(ASN1Encoding.DER);
}
catch (IOException e)
{
return new byte[0];
}
// try the outlook 2010 calculation
dig.update(spkiEnc, 0, spkiEnc.length);
dig.doFinal(hash, 0);
return hash;
}
示例3: get
import org.bouncycastle.crypto.Digest; //導入依賴的package包/類
public DigestCalculator get(final AlgorithmIdentifier algorithm)
throws OperatorCreationException
{
Digest dig = digestProvider.get(algorithm);
final DigestOutputStream stream = new DigestOutputStream(dig);
return new DigestCalculator()
{
public AlgorithmIdentifier getAlgorithmIdentifier()
{
return algorithm;
}
public OutputStream getOutputStream()
{
return stream;
}
public byte[] getDigest()
{
return stream.getDigest();
}
};
}
示例4: NTRUEncryptionKeyGenerationParameters
import org.bouncycastle.crypto.Digest; //導入依賴的package包/類
/**
* Constructs a parameter set that uses ternary private keys (i.e. </code>polyType=SIMPLE</code>).
*
* @param N number of polynomial coefficients
* @param q modulus
* @param df number of ones in the private polynomial <code>f</code>
* @param dm0 minimum acceptable number of -1's, 0's, and 1's in the polynomial <code>m'</code> in the last encryption step
* @param db number of random bits to prepend to the message
* @param c a parameter for the Index Generation Function ({@link org.bouncycastle.pqc.crypto.ntru.IndexGenerator})
* @param minCallsR minimum number of hash calls for the IGF to make
* @param minCallsMask minimum number of calls to generate the masking polynomial
* @param hashSeed whether to hash the seed in the MGF first (true) or use the seed directly (false)
* @param oid three bytes that uniquely identify the parameter set
* @param sparse whether to treat ternary polynomials as sparsely populated ({@link org.bouncycastle.pqc.math.ntru.polynomial.SparseTernaryPolynomial} vs {@link org.bouncycastle.pqc.math.ntru.polynomial.DenseTernaryPolynomial})
* @param fastFp whether <code>f=1+p*F</code> for a ternary <code>F</code> (true) or <code>f</code> is ternary (false)
* @param hashAlg a valid identifier for a <code>java.security.MessageDigest</code> instance such as <code>SHA-256</code>. The <code>MessageDigest</code> must support the <code>getDigestLength()</code> method.
*/
public NTRUEncryptionKeyGenerationParameters(int N, int q, int df, int dm0, int db, int c, int minCallsR, int minCallsMask, boolean hashSeed, byte[] oid, boolean sparse, boolean fastFp, Digest hashAlg)
{
super(new SecureRandom(), db);
this.N = N;
this.q = q;
this.df = df;
this.db = db;
this.dm0 = dm0;
this.c = c;
this.minCallsR = minCallsR;
this.minCallsMask = minCallsMask;
this.hashSeed = hashSeed;
this.oid = oid;
this.sparse = sparse;
this.fastFp = fastFp;
this.polyType = NTRUParameters.TERNARY_POLYNOMIAL_TYPE_SIMPLE;
this.hashAlg = hashAlg;
init();
}
示例5: NTRUSigningKeyGenerationParameters
import org.bouncycastle.crypto.Digest; //導入依賴的package包/類
/**
* Constructs a parameter set that uses product-form private keys (i.e. </code>polyType=PRODUCT</code>).
*
* @param N number of polynomial coefficients
* @param q modulus
* @param d1 number of -1's in the private polynomials <code>f</code> and <code>g</code>
* @param d2 number of -1's in the private polynomials <code>f</code> and <code>g</code>
* @param d3 number of -1's in the private polynomials <code>f</code> and <code>g</code>
* @param B number of perturbations
* @param basisType whether to use the standard or transpose lattice
* @param beta balancing factor for the transpose lattice
* @param normBound maximum norm for valid signatures
* @param keyNormBound maximum norm for the ploynomials <code>F</code> and <code>G</code>
* @param primeCheck whether <code>2N+1</code> is prime
* @param sparse whether to treat ternary polynomials as sparsely populated ({@link org.bouncycastle.pqc.math.ntru.polynomial.SparseTernaryPolynomial} vs {@link org.bouncycastle.pqc.math.ntru.polynomial.DenseTernaryPolynomial})
* @param keyGenAlg <code>RESULTANT</code> produces better bases, <code>FLOAT</code> is slightly faster. <code>RESULTANT</code> follows the EESS standard while <code>FLOAT</code> is described in Hoffstein et al: An Introduction to Mathematical Cryptography.
* @param hashAlg a valid identifier for a <code>java.security.MessageDigest</code> instance such as <code>SHA-256</code>. The <code>MessageDigest</code> must support the <code>getDigestLength()</code> method.
*/
public NTRUSigningKeyGenerationParameters(int N, int q, int d1, int d2, int d3, int B, int basisType, double beta, double normBound, double keyNormBound, boolean primeCheck, boolean sparse, int keyGenAlg, Digest hashAlg)
{
super(new SecureRandom(), N);
this.N = N;
this.q = q;
this.d1 = d1;
this.d2 = d2;
this.d3 = d3;
this.B = B;
this.basisType = basisType;
this.beta = beta;
this.normBound = normBound;
this.keyNormBound = keyNormBound;
this.primeCheck = primeCheck;
this.sparse = sparse;
this.keyGenAlg = keyGenAlg;
this.hashAlg = hashAlg;
polyType = NTRUParameters.TERNARY_POLYNOMIAL_TYPE_PRODUCT;
init();
}
示例6: P11DSAContentSigner
import org.bouncycastle.crypto.Digest; //導入依賴的package包/類
P11DSAContentSigner(P11CryptService cryptService, P11EntityIdentifier identityId,
AlgorithmIdentifier signatureAlgId, boolean plain)
throws XiSecurityException, P11TokenException {
this.identityId = ParamUtil.requireNonNull("identityId", identityId);
this.cryptService = ParamUtil.requireNonNull("cryptService", cryptService);
this.algorithmIdentifier = ParamUtil.requireNonNull("signatureAlgId", signatureAlgId);
try {
this.encodedAlgorithmIdentifier = algorithmIdentifier.getEncoded();
} catch (IOException ex) {
throw new XiSecurityException("could not encode AlgorithmIdentifier", ex);
}
this.plain = plain;
String algOid = signatureAlgId.getAlgorithm().getId();
HashAlgoType hashAlgo = sigAlgHashMap.get(algOid);
if (hashAlgo == null) {
throw new XiSecurityException("unsupported signature algorithm " + algOid);
}
P11SlotIdentifier slotId = identityId.slotId();
P11Slot slot = cryptService.getSlot(slotId);
if (slot.supportsMechanism(PKCS11Constants.CKM_DSA)) {
this.mechanism = PKCS11Constants.CKM_DSA;
Digest digest = hashAlgo.createDigest();
this.outputStream = new DigestOutputStream(digest);
} else {
this.mechanism = hashMechMap.get(hashAlgo).longValue();
if (!slot.supportsMechanism(this.mechanism)) {
throw new XiSecurityException("unsupported signature algorithm " + algOid);
}
this.outputStream = new ByteArrayOutputStream();
}
}
示例7: cloneHash
import org.bouncycastle.crypto.Digest; //導入依賴的package包/類
public static final Digest cloneHash(int hashAlgorithm, Digest hash)
{
switch (hashAlgorithm)
{
case HashAlgorithm.md5:
return new MD5Digest((MD5Digest)hash);
case HashAlgorithm.sha1:
return new SHA1Digest((SHA1Digest)hash);
case HashAlgorithm.sha224:
return new SHA224Digest((SHA224Digest)hash);
case HashAlgorithm.sha256:
return new SHA256Digest((SHA256Digest)hash);
case HashAlgorithm.sha384:
return new SHA384Digest((SHA384Digest)hash);
case HashAlgorithm.sha512:
return new SHA512Digest((SHA512Digest)hash);
default:
throw new IllegalArgumentException("unknown HashAlgorithm");
}
}
示例8: commit
import org.bouncycastle.crypto.Digest; //導入依賴的package包/類
public TlsHandshakeHash commit()
{
int prfAlgorithm = context.getSecurityParameters().getPrfAlgorithm();
Digest prfHash = TlsUtils.createPRFHash(prfAlgorithm);
byte[] data = buf.toByteArray();
prfHash.update(data, 0, data.length);
if (prfHash instanceof TlsHandshakeHash)
{
TlsHandshakeHash tlsPRFHash = (TlsHandshakeHash)prfHash;
tlsPRFHash.init(context);
return tlsPRFHash.commit();
}
this.prfAlgorithm = prfAlgorithm;
this.hash = prfHash;
this.buf = null;
return this;
}
示例9: OAEPEncoding
import org.bouncycastle.crypto.Digest; //導入依賴的package包/類
public OAEPEncoding(
AsymmetricBlockCipher cipher,
Digest hash,
Digest mgf1Hash,
byte[] encodingParams)
{
this.engine = cipher;
this.mgf1Hash = mgf1Hash;
this.defHash = new byte[hash.getDigestSize()];
hash.reset();
if (encodingParams != null)
{
hash.update(encodingParams, 0, encodingParams.length);
}
hash.doFinal(defHash, 0);
}
示例10: createHMACDigest
import org.bouncycastle.crypto.Digest; //導入依賴的package包/類
protected Digest createHMACDigest(int macAlgorithm)
throws IOException
{
switch (macAlgorithm)
{
case MACAlgorithm._null:
return null;
case MACAlgorithm.hmac_md5:
return new MD5Digest();
case MACAlgorithm.hmac_sha1:
return new SHA1Digest();
case MACAlgorithm.hmac_sha256:
return new SHA256Digest();
case MACAlgorithm.hmac_sha384:
return new SHA384Digest();
case MACAlgorithm.hmac_sha512:
return new SHA512Digest();
default:
throw new TlsFatalAlert(AlertDescription.internal_error);
}
}
示例11: calculateZeroKnowledgeProof
import org.bouncycastle.crypto.Digest; //導入依賴的package包/類
/**
* Calculate a zero knowledge proof of x using Schnorr's signature.
* The returned array has two elements {g^v, r = v-x*h} for x.
*/
public static BigInteger[] calculateZeroKnowledgeProof(
BigInteger p,
BigInteger q,
BigInteger g,
BigInteger gx,
BigInteger x,
String participantId,
Digest digest,
SecureRandom random)
{
BigInteger[] zeroKnowledgeProof = new BigInteger[2];
/* Generate a random v, and compute g^v */
BigInteger vMin = ZERO;
BigInteger vMax = q.subtract(ONE);
BigInteger v = BigIntegers.createRandomInRange(vMin, vMax, random);
BigInteger gv = g.modPow(v, p);
BigInteger h = calculateHashForZeroKnowledgeProof(g, gv, gx, participantId, digest); // h
zeroKnowledgeProof[0] = gv;
zeroKnowledgeProof[1] = v.subtract(x.multiply(h)).mod(q); // r = v-x*h
return zeroKnowledgeProof;
}
示例12: sign
import org.bouncycastle.crypto.Digest; //導入依賴的package包/類
private static byte[] sign() throws Exception {
RSAEngine rsa = new RSAEngine();
Digest dig = new SHA1Digest();
RSAPrivateKey privateKey = (RSAPrivateKey) getPrivate(privateKeyFilename);
BigInteger big = ((RSAKey) privateKey).getModulus();
ISO9796d2Signer eng = new ISO9796d2Signer(rsa, dig, true);
RSAKeyParameters rsaPriv = new RSAKeyParameters(true, big, privateKey.getPrivateExponent());
eng.init(true, rsaPriv);
eng.update(message[0]);
eng.update(message, 1, message.length - 1);
byte[] signature = eng.generateSignature();
return signature;
}
示例13: getByteLength
import org.bouncycastle.crypto.Digest; //導入依賴的package包/類
private static int getByteLength(
Digest digest)
{
if (digest instanceof ExtendedDigest)
{
return ((ExtendedDigest)digest).getByteLength();
}
Integer b = (Integer)blockLengths.get(digest.getAlgorithmName());
if (b == null)
{
throw new IllegalArgumentException("unknown digest passed: " + digest.getAlgorithmName());
}
return b.intValue();
}
示例14: AuthorityKeyIdentifier
import org.bouncycastle.crypto.Digest; //導入依賴的package包/類
/**
* create an AuthorityKeyIdentifier with the GeneralNames tag and
* the serial number provided as well.
*/
public AuthorityKeyIdentifier(
SubjectPublicKeyInfo spki,
GeneralNames name,
BigInteger serialNumber)
{
Digest digest = new SHA1Digest();
byte[] resBuf = new byte[digest.getDigestSize()];
byte[] bytes = spki.getPublicKeyData().getBytes();
digest.update(bytes, 0, bytes.length);
digest.doFinal(resBuf, 0);
this.keyidentifier = new DEROctetString(resBuf);
this.certissuer = GeneralNames.getInstance(name.toASN1Primitive());
this.certserno = new ASN1Integer(serialNumber);
}
示例15: createSigner
import org.bouncycastle.crypto.Digest; //導入依賴的package包/類
protected Signer createSigner(AlgorithmIdentifier sigAlgId, AlgorithmIdentifier digAlgId)
throws OperatorCreationException {
if (!AlgorithmUtil.isECSigAlg(sigAlgId)) {
throw new OperatorCreationException(
"the given algorithm is not a valid EC signature algorithm '"
+ sigAlgId.getAlgorithm().getId() + "'");
}
Digest dig = digestProvider.get(digAlgId);
ECDSASigner dsaSigner = new ECDSASigner();
return plain ? new DSAPlainDigestSigner(dsaSigner, dig)
: new DSADigestSigner(dsaSigner, dig);
}