本文整理汇总了Java中org.bouncycastle.crypto.digests.SHA256Digest.getDigestSize方法的典型用法代码示例。如果您正苦于以下问题:Java SHA256Digest.getDigestSize方法的具体用法?Java SHA256Digest.getDigestSize怎么用?Java SHA256Digest.getDigestSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bouncycastle.crypto.digests.SHA256Digest
的用法示例。
在下文中一共展示了SHA256Digest.getDigestSize方法的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: computeChallenge
import org.bouncycastle.crypto.digests.SHA256Digest; //导入方法依赖的package包/类
private BigInteger computeChallenge(ECPoint a, ECPoint b, ECPoint c, ECPoint partial, ECPoint g, ECPoint q)
{
SHA256Digest sha256 = new SHA256Digest();
addIn(sha256, a);
addIn(sha256, b);
addIn(sha256, c);
addIn(sha256, partial);
addIn(sha256, g);
addIn(sha256, q);
byte[] res = new byte[sha256.getDigestSize()];
sha256.doFinal(res, 0);
return new BigInteger(1, res);
}
示例6: computeChallenge
import org.bouncycastle.crypto.digests.SHA256Digest; //导入方法依赖的package包/类
private BigInteger computeChallenge(ECPoint a, ECPoint b, ECPoint c, ECPair partial, ECPoint g)
{
SHA256Digest sha256 = new SHA256Digest();
addIn(sha256, a);
addIn(sha256, b);
addIn(sha256, c);
addIn(sha256, partial.getX());
addIn(sha256, g);
addIn(sha256, q);
byte[] res = new byte[sha256.getDigestSize()];
sha256.doFinal(res, 0);
return new BigInteger(1, res);
}
示例7: 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;
}
示例8: 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);
}
示例9: 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;
}
示例10: 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;
}
示例11: 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;
}
示例12: 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 );
}
示例13: 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;
}
示例14: 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 );
}
示例15: validateDigest
import org.bouncycastle.crypto.digests.SHA256Digest; //导入方法依赖的package包/类
private void validateDigest(String digest, byte[] encodedState) {
SHA256Digest computedDigest = new SHA256Digest(encodedState);
byte[] computedBytes = new byte[computedDigest.getDigestSize()];
computedDigest.doFinal(computedBytes, 0);
String computed = "sha256:" + printHexBinary(computedBytes);
computed = computed.toLowerCase();
if ( ! digest.equals(computed) ) {
throw new RegistryError("Invalid digest, expected "+computed+", but got "+digest,
RegistryErrorCode.DIGEST_INVALID);
}
}