本文整理匯總了Java中org.bouncycastle.crypto.Digest.doFinal方法的典型用法代碼示例。如果您正苦於以下問題:Java Digest.doFinal方法的具體用法?Java Digest.doFinal怎麽用?Java Digest.doFinal使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.bouncycastle.crypto.Digest
的用法示例。
在下文中一共展示了Digest.doFinal方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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;
}
示例2: calculateHashForZeroKnowledgeProof
import org.bouncycastle.crypto.Digest; //導入方法依賴的package包/類
private static BigInteger calculateHashForZeroKnowledgeProof(
BigInteger g,
BigInteger gr,
BigInteger gx,
String participantId,
Digest digest)
{
digest.reset();
updateDigestIncludingSize(digest, g);
updateDigestIncludingSize(digest, gr);
updateDigestIncludingSize(digest, gx);
updateDigestIncludingSize(digest, participantId);
byte[] output = new byte[digest.getDigestSize()];
digest.doFinal(output, 0);
return new BigInteger(output);
}
示例3: calculateMacKey
import org.bouncycastle.crypto.Digest; //導入方法依賴的package包/類
/**
* Calculates the MacKey (i.e. the key to use when calculating the MagTag for key confirmation).
* <p/>
* <p/>
* <pre>
* MacKey = H(K || "JPAKE_KC")
* </pre>
*/
private static byte[] calculateMacKey(BigInteger keyingMaterial, Digest digest)
{
digest.reset();
updateDigest(digest, keyingMaterial);
/*
* This constant is used to ensure that the macKey is NOT the same as the derived key.
*/
updateDigest(digest, "JPAKE_KC");
byte[] output = new byte[digest.getDigestSize()];
digest.doFinal(output, 0);
return output;
}
示例4: 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);
}
示例5: calcHash
import org.bouncycastle.crypto.Digest; //導入方法依賴的package包/類
private byte[] calcHash(Digest hashAlg)
{
byte[] tmp = new byte[hashAlg.getDigestSize()];
hashAlg.doFinal(tmp, 0);
return tmp;
}
示例6: generateServerKeyExchange
import org.bouncycastle.crypto.Digest; //導入方法依賴的package包/類
public byte[] generateServerKeyExchange()
throws IOException
{
if (this.dhParameters == null)
{
throw new TlsFatalAlert(AlertDescription.internal_error);
}
ByteArrayOutputStream buf = new ByteArrayOutputStream();
DHKeyPairGenerator kpg = new DHKeyPairGenerator();
kpg.init(new DHKeyGenerationParameters(context.getSecureRandom(), this.dhParameters));
AsymmetricCipherKeyPair kp = kpg.generateKeyPair();
BigInteger Ys = ((DHPublicKeyParameters)kp.getPublic()).getY();
TlsDHUtils.writeDHParameter(dhParameters.getP(), buf);
TlsDHUtils.writeDHParameter(dhParameters.getG(), buf);
TlsDHUtils.writeDHParameter(Ys, buf);
byte[] digestInput = buf.toByteArray();
Digest d = new CombinedHash();
SecurityParameters securityParameters = context.getSecurityParameters();
d.update(securityParameters.clientRandom, 0, securityParameters.clientRandom.length);
d.update(securityParameters.serverRandom, 0, securityParameters.serverRandom.length);
d.update(digestInput, 0, digestInput.length);
byte[] hash = new byte[d.getDigestSize()];
d.doFinal(hash, 0);
byte[] sigBytes = serverCredentials.generateCertificateSignature(hash);
/*
* TODO RFC 5246 4.7. digitally-signed element needs SignatureAndHashAlgorithm prepended from TLS 1.2
*/
TlsUtils.writeOpaque16(sigBytes, buf);
return buf.toByteArray();
}
示例7: calculateKeyBlock_SSL
import org.bouncycastle.crypto.Digest; //導入方法依賴的package包/類
static byte[] calculateKeyBlock_SSL(byte[] master_secret, byte[] random, int size)
{
Digest md5 = new MD5Digest();
Digest sha1 = new SHA1Digest();
int md5Size = md5.getDigestSize();
byte[] shatmp = new byte[sha1.getDigestSize()];
byte[] tmp = new byte[size + md5Size];
int i = 0, pos = 0;
while (pos < size)
{
byte[] ssl3Const = SSL3_CONST[i];
sha1.update(ssl3Const, 0, ssl3Const.length);
sha1.update(master_secret, 0, master_secret.length);
sha1.update(random, 0, random.length);
sha1.doFinal(shatmp, 0);
md5.update(master_secret, 0, master_secret.length);
md5.update(shatmp, 0, shatmp.length);
md5.doFinal(tmp, pos);
pos += md5Size;
++i;
}
byte rval[] = new byte[size];
System.arraycopy(tmp, 0, rval, 0, size);
return rval;
}
示例8: calculateMasterSecret_SSL
import org.bouncycastle.crypto.Digest; //導入方法依賴的package包/類
static byte[] calculateMasterSecret_SSL(byte[] pre_master_secret, byte[] random)
{
Digest md5 = new MD5Digest();
Digest sha1 = new SHA1Digest();
int md5Size = md5.getDigestSize();
byte[] shatmp = new byte[sha1.getDigestSize()];
byte[] rval = new byte[md5Size * 3];
int pos = 0;
for (int i = 0; i < 3; ++i)
{
byte[] ssl3Const = SSL3_CONST[i];
sha1.update(ssl3Const, 0, ssl3Const.length);
sha1.update(pre_master_secret, 0, pre_master_secret.length);
sha1.update(random, 0, random.length);
sha1.doFinal(shatmp, 0);
md5.update(pre_master_secret, 0, pre_master_secret.length);
md5.update(shatmp, 0, shatmp.length);
md5.doFinal(rval, pos);
pos += md5Size;
}
return rval;
}
示例9: ssl3Complete
import org.bouncycastle.crypto.Digest; //導入方法依賴的package包/類
protected void ssl3Complete(Digest d, byte[] ipad, byte[] opad, int padLength)
{
byte[] secret = context.getSecurityParameters().masterSecret;
d.update(secret, 0, secret.length);
d.update(ipad, 0, padLength);
byte[] tmp = new byte[d.getDigestSize()];
d.doFinal(tmp, 0);
d.update(secret, 0, secret.length);
d.update(opad, 0, padLength);
d.update(tmp, 0, tmp.length);
}
示例10: calculateX
import org.bouncycastle.crypto.Digest; //導入方法依賴的package包/類
public static BigInteger calculateX(Digest digest, BigInteger N, byte[] salt, byte[] identity, byte[] password)
{
byte[] output = new byte[digest.getDigestSize()];
digest.update(identity, 0, identity.length);
digest.update((byte)':');
digest.update(password, 0, password.length);
digest.doFinal(output, 0);
digest.update(salt, 0, salt.length);
digest.update(output, 0, output.length);
digest.doFinal(output, 0);
return new BigInteger(1, output);
}
示例11: hash
import org.bouncycastle.crypto.Digest; //導入方法依賴的package包/類
/**
* Hash the data and returns the first 8 bytes of the hash value.
* @param data data over which the hash value is calculated.
* @return long represented of the first 8 bytes
*/
public static long hash(byte[] data) {
ParamUtil.requireNonNull("data", data);
ConcurrentBagEntry<Digest> md0 = null;
for (int i = 0; i < 3; i++) {
try {
md0 = MDS.borrow(10, TimeUnit.SECONDS);
break;
} catch (InterruptedException ex) { // CHECKSTYLE:SKIP
}
}
if (md0 == null) {
throw new RuntimeOperatorException("could not get idle MessageDigest");
}
try {
Digest md = md0.value();
md.reset();
md.update(data, 0, data.length);
byte[] bytes = new byte[md.getDigestSize()];
md.doFinal(bytes, 0);
return bytesToLong(bytes);
} finally {
MDS.requite(md0);
}
}
示例12: getDigest
import org.bouncycastle.crypto.Digest; //導入方法依賴的package包/類
public byte[] getDigest()
{
byte[] bytes = bOut.toByteArray();
bOut.reset();
Digest sha1 = new SHA1Digest();
sha1.update(bytes, 0, bytes.length);
byte[] digest = new byte[sha1.getDigestSize()];
sha1.doFinal(digest, 0);
return digest;
}
示例13: doFinal
import org.bouncycastle.crypto.Digest; //導入方法依賴的package包/類
private static byte[] doFinal(Digest d)
{
byte[] bs = new byte[d.getDigestSize()];
d.doFinal(bs, 0);
return bs;
}
示例14: modifyBytes
import org.bouncycastle.crypto.Digest; //導入方法依賴的package包/類
public byte[] modifyBytes(byte[] input) throws ModificationException{
// Get the selected ByteModifier and use the modifyBytes method from their to update input.
Digest digest;
byte[] output;
if (algoComboBox.getSelectedItem().equals("MD2")) {
digest = new MD2Digest();
output = new byte[digest.getDigestSize()];
} else if (algoComboBox.getSelectedItem().equals("MD4")) {
digest = new MD4Digest();
output = new byte[digest.getDigestSize()];
} else if (algoComboBox.getSelectedItem().equals("MD5")) {
digest = new MD5Digest();
output = new byte[digest.getDigestSize()];
} else if (algoComboBox.getSelectedItem().equals("Keccak")) {
digest = new KeccakDigest(Integer.parseInt((String)keccakComboBox.getSelectedItem()));
output = new byte[digest.getDigestSize()];
} else if (algoComboBox.getSelectedItem().equals("RIPEMD128")) {
digest = new RIPEMD128Digest();
output = new byte[digest.getDigestSize()];
} else if (algoComboBox.getSelectedItem().equals("RIPEMD160")) {
digest = new RIPEMD160Digest();
output = new byte[digest.getDigestSize()];
} else if (algoComboBox.getSelectedItem().equals("RIPEMD256")) {
digest = new RIPEMD256Digest();
output = new byte[digest.getDigestSize()];
} else if (algoComboBox.getSelectedItem().equals("RIPEMD320")) {
digest = new RIPEMD320Digest();
output = new byte[digest.getDigestSize()];
} else if (algoComboBox.getSelectedItem().equals("SHA1")) {
digest = new SHA1Digest();
output = new byte[digest.getDigestSize()];
} else if (algoComboBox.getSelectedItem().equals("SHA224")) {
digest = new SHA224Digest();
output = new byte[digest.getDigestSize()];
} else if (algoComboBox.getSelectedItem().equals("SHA256")) {
digest = new SHA256Digest();
output = new byte[digest.getDigestSize()];
} else if (algoComboBox.getSelectedItem().equals("SHA384")) {
digest = new SHA384Digest();
output = new byte[digest.getDigestSize()];
} else if (algoComboBox.getSelectedItem().equals("SHA3")) {
digest = new SHA3Digest(Integer.parseInt((String)sha3ComboBox.getSelectedItem()));
output = new byte[digest.getDigestSize()];
} else if (algoComboBox.getSelectedItem().equals("SHAKE")) {
digest = new SHAKEDigest(Integer.parseInt((String)shakeComboBox.getSelectedItem()));
output = new byte[digest.getDigestSize()];
} else if (algoComboBox.getSelectedItem().equals("SM3")) {
digest = new SM3Digest();
output = new byte[digest.getDigestSize()];
} else if (algoComboBox.getSelectedItem().equals("Tiger")) {
digest = new TigerDigest();
output = new byte[digest.getDigestSize()];
} else if (algoComboBox.getSelectedItem().equals("GOST3411")) {
digest = new GOST3411Digest();
output = new byte[digest.getDigestSize()];
} else {
digest = new WhirlpoolDigest();
output = new byte[digest.getDigestSize()];
}
// KeccakDigest 224, 256, 288, 384, 512
// SHA3Digest 224, 256, 384, 512
// SHAKEDigest 128, 256
digest.reset();
digest.update(input, 0, input.length);
digest.doFinal(output, 0);
return output;
}
示例15: hash_df
import org.bouncycastle.crypto.Digest; //導入方法依賴的package包/類
/**
* Used by both Dual EC and Hash.
*/
static byte[] hash_df(Digest digest, byte[] seedMaterial, int seedLength)
{
// 1. temp = the Null string.
// 2. .
// 3. counter = an 8-bit binary value representing the integer "1".
// 4. For i = 1 to len do
// Comment : In step 4.1, no_of_bits_to_return
// is used as a 32-bit string.
// 4.1 temp = temp || Hash (counter || no_of_bits_to_return ||
// input_string).
// 4.2 counter = counter + 1.
// 5. requested_bits = Leftmost (no_of_bits_to_return) of temp.
// 6. Return SUCCESS and requested_bits.
byte[] temp = new byte[(seedLength + 7) / 8];
int len = temp.length / digest.getDigestSize();
int counter = 1;
byte[] dig = new byte[digest.getDigestSize()];
for (int i = 0; i <= len; i++)
{
digest.update((byte)counter);
digest.update((byte)(seedLength >> 24));
digest.update((byte)(seedLength >> 16));
digest.update((byte)(seedLength >> 8));
digest.update((byte)seedLength);
digest.update(seedMaterial, 0, seedMaterial.length);
digest.doFinal(dig, 0);
int bytesToCopy = ((temp.length - i * dig.length) > dig.length)
? dig.length
: (temp.length - i * dig.length);
System.arraycopy(dig, 0, temp, i * dig.length, bytesToCopy);
counter++;
}
// do a left shift to get rid of excess bits.
if (seedLength % 8 != 0)
{
int shift = 8 - (seedLength % 8);
int carry = 0;
for (int i = 0; i != temp.length; i++)
{
int b = temp[i] & 0xff;
temp[i] = (byte)((b >>> shift) | (carry << (8 - shift)));
carry = b;
}
}
return temp;
}