本文整理匯總了Java中org.bouncycastle.crypto.Digest.update方法的典型用法代碼示例。如果您正苦於以下問題:Java Digest.update方法的具體用法?Java Digest.update怎麽用?Java Digest.update使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.bouncycastle.crypto.Digest
的用法示例。
在下文中一共展示了Digest.update方法的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: 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;
}
示例3: 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);
}
示例4: putInt
import org.bouncycastle.crypto.Digest; //導入方法依賴的package包/類
private void putInt(Digest hashAlg, int counter)
{
hashAlg.update((byte)(counter >> 24));
hashAlg.update((byte)(counter >> 16));
hashAlg.update((byte)(counter >> 8));
hashAlg.update((byte)counter);
}
示例5: getDigest
import org.bouncycastle.crypto.Digest; //導入方法依賴的package包/類
private static byte[] getDigest(SubjectPublicKeyInfo spki)
{
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);
return resBuf;
}
示例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: updateDigestIncludingSize
import org.bouncycastle.crypto.Digest; //導入方法依賴的package包/類
private static void updateDigestIncludingSize(Digest digest, BigInteger bigInteger)
{
byte[] byteArray = BigIntegers.asUnsignedByteArray(bigInteger);
digest.update(intToByteArray(byteArray.length), 0, 4);
digest.update(byteArray, 0, byteArray.length);
Arrays.fill(byteArray, (byte)0);
}
示例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: hash
import org.bouncycastle.crypto.Digest; //導入方法依賴的package包/類
static byte[] hash(byte[] message, int ofs, int len, Digest alg) {
byte[] res = new byte[alg.getDigestSize()];
alg.update(message, ofs, len);
alg.doFinal(res, 0);
return res;
}
示例14: addFieldElement
import org.bouncycastle.crypto.Digest; //導入方法依賴的package包/類
private static void addFieldElement(Digest digest, ECFieldElement v)
{
byte[] p = v.getEncoded();
digest.update(p, 0, p.length);
}
示例15: updateDigest
import org.bouncycastle.crypto.Digest; //導入方法依賴的package包/類
private static void updateDigest(Digest digest, String string)
{
byte[] byteArray = Strings.toUTF8ByteArray(string);
digest.update(byteArray, 0, byteArray.length);
Arrays.fill(byteArray, (byte)0);
}