本文整理了Java中org.bouncycastle.crypto.digests.SHA256Digest
类的一些代码示例,展示了SHA256Digest
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SHA256Digest
类的具体详情如下:
包路径:org.bouncycastle.crypto.digests.SHA256Digest
类名称:SHA256Digest
[英]FIPS 180-2 implementation of SHA-256.
block word digest
SHA-1 512 32 160
SHA-256 512 32 256
SHA-384 1024 64 384
SHA-512 1024 64 512
[中]FIPS 180-2 SHA-256的实施
block word digest
SHA-1 512 32 160
SHA-256 512 32 256
SHA-384 1024 64 384
SHA-512 1024 64 512
代码示例来源:origin: stackoverflow.com
PKCS5S2ParametersGenerator gen = new PKCS5S2ParametersGenerator(new SHA256Digest());
gen.init("password".getBytes("UTF-8"), "salt".getBytes(), 4096);
byte[] dk = ((KeyParameter) gen.generateDerivedParameters(256)).getKey();
代码示例来源:origin: org.opendaylight.usc/usc-channel-impl
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;
}
代码示例来源:origin: puppetlabs/europa
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);
}
}
}
代码示例来源:origin: io.github.in-toto/in-toto
/**
* Returns the signer associated with the signing method for this key
*
* @return a Signer instance that can be used to sign or verify using
* RSASSA-PSS
*/
public Signer getSigner() {
RSAEngine engine = new RSAEngine();
try {
engine.init(false, getPrivate());
} catch (IOException e) {
throw new RuntimeException(e.toString());
}
SHA256Digest digest = new SHA256Digest();
return new PSSSigner(engine, digest, digest.getDigestSize());
}
}
代码示例来源:origin: org.bouncycastle/bcprov-debug-jdk15on
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);
}
}
代码示例来源:origin: cloudfoundry/uaa
private byte[] generateKey(byte[] salt) throws UnsupportedEncodingException {
PKCS5S2ParametersGenerator gen = new PKCS5S2ParametersGenerator(new SHA256Digest());
gen.init(this.passphrase.getBytes("UTF-8"), salt, PBKDF2_ITERATIONS);
return ((KeyParameter) gen.generateDerivedParameters(AES_KEY_LENGTH_BITS)).getKey();
}
}
代码示例来源:origin: redfish64/TinyTravelTracker
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);
}
}
代码示例来源:origin: web3j/web3j
private static byte[] generateAes128CtrDerivedKey(
byte[] password, byte[] salt, int c, String prf) throws CipherException {
if (!prf.equals("hmac-sha256")) {
throw new CipherException("Unsupported prf:" + prf);
}
// Java 8 supports this, but you have to convert the password to a character array, see
// http://stackoverflow.com/a/27928435/3211687
PKCS5S2ParametersGenerator gen = new PKCS5S2ParametersGenerator(new SHA256Digest());
gen.init(password, salt, c);
return ((KeyParameter) gen.generateDerivedParameters(256)).getKey();
}
代码示例来源:origin: io.github.in-toto/in-toto
/**
* Convenience method to obtain the keyid for this key
*
* @return the keyid for this key (Sha256 is baked in, for the time being)
*/
public String computeKeyId() {
if (this.kpr == null)
return null;
byte[] JSONrepr = getJSONEncodeableFields();
// initialize digest
SHA256Digest digest = new SHA256Digest();
byte[] result = new byte[digest.getDigestSize()];
digest.update(JSONrepr, 0, JSONrepr.length);
digest.doFinal(result, 0);
return Hex.toHexString(result);
}
代码示例来源:origin: web3j/web3j
/**
* Sign a hash with the private key of this key pair.
* @param transactionHash the hash to sign
* @return An {@link ECDSASignature} of the hash
*/
public ECDSASignature sign(byte[] transactionHash) {
ECDSASigner signer = new ECDSASigner(new HMacDSAKCalculator(new SHA256Digest()));
ECPrivateKeyParameters privKey = new ECPrivateKeyParameters(privateKey, Sign.CURVE);
signer.init(true, privKey);
BigInteger[] components = signer.generateSignature(transactionHash);
return new ECDSASignature(components[0], components[1]).toCanonicalised();
}
代码示例来源:origin: horrorho/InflatableDonkey
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);
}
}
代码示例来源:origin: apache/nifi
private Digest resolvePRF(final String prf) {
if (StringUtils.isEmpty(prf)) {
throw new IllegalArgumentException("Cannot resolve empty PRF");
}
String formattedPRF = prf.toLowerCase().replaceAll("[\\W]+", "");
logger.debug("Resolved PRF {} to {}", prf, formattedPRF);
switch (formattedPRF) {
case "md5":
return new MD5Digest();
case "sha1":
return new SHA1Digest();
case "sha384":
return new SHA384Digest();
case "sha256":
return new SHA256Digest();
case "sha512":
return new SHA512Digest();
default:
logger.warn("Could not resolve PRF {}. Using default PRF {} instead", prf, DEFAULT_PRF);
return new SHA512Digest();
}
}
}
代码示例来源:origin: io.github.in-toto/in-toto
private void collect(String filename) {
FileInputStream file = null;
try {
file = new FileInputStream(filename);
} catch (FileNotFoundException e) {
throw new RuntimeException("The file " + filename + " couldn't be recorded");
}
SHA256Digest digest = new SHA256Digest();
byte[] result = new byte[digest.getDigestSize()];
int length;
try {
while ((length = file.read(result)) != -1) {
digest.update(result, 0, length);
}
} catch (IOException e) {
throw new RuntimeException("The file " + filename + " couldn't be recorded");
}
digest.doFinal(result, 0);
// We should be able to submit more hashes, but we will do sha256
// only for the time being
this.put("sha256", Hex.toHexString(result));
}
}
代码示例来源:origin: hyperledger/fabric-sdk-java
private Digest getHashDigest() {
if ("SHA3".equals(hashAlgorithm)) {
return new SHA3Digest();
} else {
// Default to SHA2
return new SHA256Digest();
}
}
代码示例来源:origin: horrorho/LiquidDonkey
byte[] shared = Curve25519.create().agreement(otherPublicKey, myPrivateKey);
byte[] pad = new byte[]{0x00, 0x00, 0x00, 0x01};
byte[] hash = new byte[sha256.getDigestSize()];
sha256.reset();
sha256.update(pad, 0, pad.length);
sha256.update(shared, 0, shared.length);
sha256.update(otherPublicKey, 0, otherPublicKey.length);
sha256.update(myPublicKey, 0, myPublicKey.length);
sha256.doFinal(hash, 0);
代码示例来源:origin: hyperledger/fabric-sdk-java
byte[] getClientTLSCertificateDigest() {
//The digest must be SHA256 over the DER encoded certificate. The PEM has the exact DER sequence in hex encoding around the begin and end markers
if (tlsClientCertificatePEMBytes != null && clientTLSCertificateDigest == null) {
String pemCert = new String(tlsClientCertificatePEMBytes, UTF_8);
byte[] derBytes = Base64.getDecoder().decode(
pemCert.replaceAll("-+[ \t]*(BEGIN|END)[ \t]+CERTIFICATE[ \t]*-+", "").replaceAll("\\s", "").trim()
);
Digest digest = new SHA256Digest();
clientTLSCertificateDigest = new byte[digest.getDigestSize()];
digest.update(derBytes, 0, derBytes.length);
digest.doFinal(clientTLSCertificateDigest, 0);
}
return clientTLSCertificateDigest;
}
代码示例来源:origin: stackoverflow.com
SHA256Digest digester = new SHA256Digest();
byte[] retValue = new byte[digester.getDigestSize()];
digester.update(key.getBytes(), 0, key.length());
digester.doFinal(retValue,0);
代码示例来源:origin: stackoverflow.com
PKCS5S2ParametersGenerator generator = new PKCS5S2ParametersGenerator(new SHA256Digest());
generator.init(PBEParametersGenerator.PKCS5PasswordToUTF8Bytes(password), salt, iterations);
KeyParameter key = (KeyParameter)generator.generateDerivedMacParameters(keySizeInBits);
代码示例来源:origin: stackoverflow.com
private byte[] decryptWithLWCrypto(byte[] cipher, String password, byte[] salt, final int iterationCount)
throws Exception
{
PKCS12ParametersGenerator pGen = new PKCS12ParametersGenerator(new SHA256Digest());
char[] passwordChars = password.toCharArray();
final byte[] pkcs12PasswordBytes = PBEParametersGenerator
.PKCS12PasswordToBytes(passwordChars);
pGen.init(pkcs12PasswordBytes, salt, iterationCount);
CBCBlockCipher aesCBC = new CBCBlockCipher(new AESEngine());
ParametersWithIV aesCBCParams = (ParametersWithIV) pGen.generateDerivedParameters(256, 128);
aesCBC.init(false, aesCBCParams);
PaddedBufferedBlockCipher aesCipher = new PaddedBufferedBlockCipher(aesCBC,
new PKCS7Padding());
byte[] plainTemp = new byte[aesCipher.getOutputSize(cipher.length)];
int offset = aesCipher.processBytes(cipher, 0, cipher.length, plainTemp, 0);
int last = aesCipher.doFinal(plainTemp, offset);
final byte[] plain = new byte[offset + last];
System.arraycopy(plainTemp, 0, plain, 0, plain.length);
return plain;
}
代码示例来源:origin: stackoverflow.com
Digest md = new SHA256Digest()
md.reset();
md.update(data, 0, data.length);
byte[] hash = new byte[md.getDigestSize()];
md.doFinal(hash, 0);
内容来源于网络,如有侵权,请联系作者删除!