本文整理汇总了Java中org.bouncycastle.crypto.digests.SHA256Digest.update方法的典型用法代码示例。如果您正苦于以下问题:Java SHA256Digest.update方法的具体用法?Java SHA256Digest.update怎么用?Java SHA256Digest.update使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.crypto.digests.SHA256Digest
的用法示例。
在下文中一共展示了SHA256Digest.update方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deriveSessionKey
import org.bouncycastle.crypto.digests.SHA256Digest; //导入方法依赖的package包/类
private static BigInteger deriveSessionKey(BigInteger keyingMaterial)
{
/*
* You should use a secure key derivation function (KDF) to derive the session key.
*
* For the purposes of this example, I'm just going to use a hash of the keying material.
*/
SHA256Digest digest = new SHA256Digest();
byte[] keyByteArray = keyingMaterial.toByteArray();
byte[] output = new byte[digest.getDigestSize()];
digest.update(keyByteArray, 0, keyByteArray.length);
digest.doFinal(output, 0);
return new BigInteger(output);
}
示例2: curve25519Unwrap
import org.bouncycastle.crypto.digests.SHA256Digest; //导入方法依赖的package包/类
public static Optional<byte[]> curve25519Unwrap(
byte[] myPublicKey,
byte[] myPrivateKey,
byte[] otherPublicKey,
byte[] wrappedKey) {
SHA256Digest sha256 = new SHA256Digest();
byte[] shared = Curve25519.agreement(otherPublicKey, myPrivateKey);
logger.debug("-- curve25519Unwrap() - shared agreement: 0x{}", Hex.toHexString(shared));
// Stripped down NIST SP 800-56A KDF.
byte[] counter = new byte[]{0x00, 0x00, 0x00, 0x01};
byte[] hash = new byte[sha256.getDigestSize()];
sha256.reset();
sha256.update(counter, 0, counter.length);
sha256.update(shared, 0, shared.length);
sha256.update(otherPublicKey, 0, otherPublicKey.length);
sha256.update(myPublicKey, 0, myPublicKey.length);
sha256.doFinal(hash, 0);
logger.debug("-- curve25519Unwrap() - kek: {}", Hex.toHexString(hash));
return RFC3394Wrap.unwrapAES(hash, wrappedKey);
}
示例3: main
import org.bouncycastle.crypto.digests.SHA256Digest; //导入方法依赖的package包/类
public static void main(String args[]) {
byte[] digest = new byte[4096];
for (int i = 0; i < digest.length; i++) {
digest[i] = (byte)i;
}
long start = JVM.monotonicTimeMillis();
for (int i = 0; i < 20; i++) {
SHA256Digest digester = new SHA256Digest();
byte[] retValue = new byte[digester.getDigestSize()];
for (int j = 0; j < UPDATES; j++) {
digester.update(digest, 0, digest.length);
}
digester.doFinal(retValue, 0);
}
long time = JVM.monotonicTimeMillis() - start;
System.out.println("BouncyCastleSHA256: " + time);
}
示例4: test
import org.bouncycastle.crypto.digests.SHA256Digest; //导入方法依赖的package包/类
public void test(TestHarness th) {
SHA256Digest md = new SHA256Digest();
byte[] retValue = new byte[md.getDigestSize()];
for (int i = 0; i < messages.length; i++) {
byte[] bytes = messages[i].getBytes();
md.update(bytes, 0, bytes.length);
md.doFinal(retValue, 0);
th.check(Util.hexEncode(retValue).toLowerCase(), digests[i]);
}
for (int i = 0; i < 1000000; i++) {
md.update((byte)'a');
}
md.doFinal(retValue, 0);
th.check(Util.hexEncode(retValue).toLowerCase(), MILLION_A_DIGEST);
}
示例5: generatePackPoint
import org.bouncycastle.crypto.digests.SHA256Digest; //导入方法依赖的package包/类
private ECPoint generatePackPoint(SHA256Digest digest, byte[] ballot, byte[] hash)
{
BigInteger element;
ECPoint point;
do
{
digest.update(seed, 0, seed.length);
for (int b = 0; b != ballot.length; b++)
{
digest.update(ballot[b]);
}
digest.doFinal(hash, 0);
digest.update(hash, 0, hash.length);
element = new BigInteger(1, hash).mod(domainParameters.getN());
point = domainParameters.getG().multiply(element).normalize();
}
while (element.equals(BigInteger.ZERO) || packMap.containsKey(point));
return point;
}
示例6: sha256DigestOf
import org.bouncycastle.crypto.digests.SHA256Digest; //导入方法依赖的package包/类
private static byte[] sha256DigestOf(byte[] input) {
SHA256Digest d = new SHA256Digest();
d.update(input,
0,
input.length);
byte[] result = new byte[d.getDigestSize()];
d.doFinal(result,
0);
return result;
}
示例7: calcHash
import org.bouncycastle.crypto.digests.SHA256Digest; //导入方法依赖的package包/类
private byte[] calcHash(byte[] input, AtomicLong counter) {
SHA256Digest digest = new SHA256Digest();
byte[] result = new byte[digest.getDigestSize()];
digest.update(ByteBuffer.allocate(8).order(ByteOrder.LITTLE_ENDIAN).putLong(counter.getAndIncrement()).array(), 0, 8);
digest.update(input, 0, input.length);
digest.update(this.key, 0, this.key.length);
digest.doFinal(result, 0);
return Arrays.copyOf(result, 8);
}
示例8: hashSHA256
import org.bouncycastle.crypto.digests.SHA256Digest; //导入方法依赖的package包/类
private byte[] hashSHA256(byte[]... message) {
SHA256Digest digest = new SHA256Digest();
byte[] result = new byte[digest.getDigestSize()];
for (byte[] bytes : message) {
digest.update(bytes, 0, bytes.length);
}
digest.doFinal(result, 0);
return result;
}
示例9: sha256Digest
import org.bouncycastle.crypto.digests.SHA256Digest; //导入方法依赖的package包/类
public static byte[] sha256Digest(byte[] input) {
SHA256Digest digest = new SHA256Digest();
digest.update(input, 0, input.length);
byte[] result = new byte[digest.getDigestSize()];
digest.doFinal(result, 0);
return result;
}
示例10: SHA256hash
import org.bouncycastle.crypto.digests.SHA256Digest; //导入方法依赖的package包/类
/************
* This is the SHA-256 hashing function that is performed on the public key
* @param tobeHashed - Byte Array that will be hashed
* @return - The hashed Byte Array is returned in a Byte Array
*/
private byte[] SHA256hash(byte[] tobeHashed){
SHA256Digest digester=new SHA256Digest();
byte[] retValue=new byte[digester.getDigestSize()];
digester.update(tobeHashed, 0, tobeHashed.length);
digester.doFinal(retValue, 0);
return retValue;
}
示例11: calcHash
import org.bouncycastle.crypto.digests.SHA256Digest; //导入方法依赖的package包/类
private byte[] calcHash( byte[] input, AtomicLong counter ) {
SHA256Digest digest = new SHA256Digest();
byte[] result = new byte[digest.getDigestSize()];
digest.update( ByteBuffer.allocate( 8 ).order( ByteOrder.LITTLE_ENDIAN ).putLong( counter.getAndIncrement() ).array(), 0, 8 );
digest.update( input, 0, input.length );
digest.update( this.key, 0, this.key.length );
digest.doFinal( result, 0 );
return Arrays.copyOf( result, 8 );
}
示例12: hashSHA256
import org.bouncycastle.crypto.digests.SHA256Digest; //导入方法依赖的package包/类
private byte[] hashSHA256( byte[]... message ) {
SHA256Digest digest = new SHA256Digest();
byte[] result = new byte[digest.getDigestSize()];
for ( byte[] bytes : message ) {
digest.update( bytes, 0, bytes.length );
}
digest.doFinal( result, 0 );
return result;
}
示例13: calcHash
import org.bouncycastle.crypto.digests.SHA256Digest; //导入方法依赖的package包/类
private byte[] calcHash( byte[] input, byte[] key, AtomicLong counter ) {
SHA256Digest digest = new SHA256Digest();
byte[] result = new byte[digest.getDigestSize()];
digest.update( ByteBuffer.allocate( 8 ).order( ByteOrder.LITTLE_ENDIAN ).putLong( counter.getAndIncrement() ).array(), 0, 8 );
digest.update( input, 0, input.length );
digest.update( key, 0, key.length );
digest.doFinal( result, 0 );
return Arrays.copyOf( result, 8 );
}
示例14: getAES256Key
import org.bouncycastle.crypto.digests.SHA256Digest; //导入方法依赖的package包/类
/**
* Erzeugt AES-256 Schlüssel
*
* @return Schlüssel als Byte-Array
*/
public byte[] getAES256Key() {
byte[] checksum = new byte[32];
SHA256Digest sha256 = new SHA256Digest();
sha256.update(mergedData, 0, mergedData.length);
sha256.doFinal(checksum, 0);
return checksum;
}
示例15: generateKey
import org.bouncycastle.crypto.digests.SHA256Digest; //导入方法依赖的package包/类
/** it is expected this key will not change for duration of the program */
private static final byte[] generateKey() throws Exception
{
SHA256Digest d = new SHA256Digest();
d.update((byte)staticEntropy1);
d.update((byte)staticEntropy2);
d.update((byte)staticEntropy3);
d.update((byte)staticEntropy4);
update(d, Object.class.hashCode());
update(d, String.class.hashCode());
update(d, MemCrypt.class.hashCode());
byte[] b = new byte[d.getDigestSize()];
d.doFinal(b, 0);
return b;
}