本文整理汇总了Java中org.bouncycastle.crypto.digests.SHA256Digest类的典型用法代码示例。如果您正苦于以下问题:Java SHA256Digest类的具体用法?Java SHA256Digest怎么用?Java SHA256Digest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SHA256Digest类属于org.bouncycastle.crypto.digests包,在下文中一共展示了SHA256Digest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createHash
import org.bouncycastle.crypto.digests.SHA256Digest; //导入依赖的package包/类
public static final Digest createHash(int hashAlgorithm)
{
switch (hashAlgorithm)
{
case HashAlgorithm.md5:
return new MD5Digest();
case HashAlgorithm.sha1:
return new SHA1Digest();
case HashAlgorithm.sha224:
return new SHA224Digest();
case HashAlgorithm.sha256:
return new SHA256Digest();
case HashAlgorithm.sha384:
return new SHA384Digest();
case HashAlgorithm.sha512:
return new SHA512Digest();
default:
throw new IllegalArgumentException("unknown HashAlgorithm");
}
}
示例2: cloneHash
import org.bouncycastle.crypto.digests.SHA256Digest; //导入依赖的package包/类
public static final Digest cloneHash(int hashAlgorithm, Digest hash)
{
switch (hashAlgorithm)
{
case HashAlgorithm.md5:
return new MD5Digest((MD5Digest)hash);
case HashAlgorithm.sha1:
return new SHA1Digest((SHA1Digest)hash);
case HashAlgorithm.sha224:
return new SHA224Digest((SHA224Digest)hash);
case HashAlgorithm.sha256:
return new SHA256Digest((SHA256Digest)hash);
case HashAlgorithm.sha384:
return new SHA384Digest((SHA384Digest)hash);
case HashAlgorithm.sha512:
return new SHA512Digest((SHA512Digest)hash);
default:
throw new IllegalArgumentException("unknown HashAlgorithm");
}
}
示例3: createHMACDigest
import org.bouncycastle.crypto.digests.SHA256Digest; //导入依赖的package包/类
protected Digest createHMACDigest(int macAlgorithm)
throws IOException
{
switch (macAlgorithm)
{
case MACAlgorithm._null:
return null;
case MACAlgorithm.hmac_md5:
return new MD5Digest();
case MACAlgorithm.hmac_sha1:
return new SHA1Digest();
case MACAlgorithm.hmac_sha256:
return new SHA256Digest();
case MACAlgorithm.hmac_sha384:
return new SHA384Digest();
case MACAlgorithm.hmac_sha512:
return new SHA512Digest();
default:
throw new TlsFatalAlert(AlertDescription.internal_error);
}
}
示例4: 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);
}
示例5: createHash
import org.bouncycastle.crypto.digests.SHA256Digest; //导入依赖的package包/类
public static Digest createHash(short hashAlgorithm)
{
switch (hashAlgorithm)
{
case HashAlgorithm.md5:
return new MD5Digest();
case HashAlgorithm.sha1:
return new SHA1Digest();
case HashAlgorithm.sha224:
return new SHA224Digest();
case HashAlgorithm.sha256:
return new SHA256Digest();
case HashAlgorithm.sha384:
return new SHA384Digest();
case HashAlgorithm.sha512:
return new SHA512Digest();
default:
throw new IllegalArgumentException("unknown HashAlgorithm");
}
}
示例6: cloneHash
import org.bouncycastle.crypto.digests.SHA256Digest; //导入依赖的package包/类
public static Digest cloneHash(short hashAlgorithm, Digest hash)
{
switch (hashAlgorithm)
{
case HashAlgorithm.md5:
return new MD5Digest((MD5Digest)hash);
case HashAlgorithm.sha1:
return new SHA1Digest((SHA1Digest)hash);
case HashAlgorithm.sha224:
return new SHA224Digest((SHA224Digest)hash);
case HashAlgorithm.sha256:
return new SHA256Digest((SHA256Digest)hash);
case HashAlgorithm.sha384:
return new SHA384Digest((SHA384Digest)hash);
case HashAlgorithm.sha512:
return new SHA512Digest((SHA512Digest)hash);
default:
throw new IllegalArgumentException("unknown HashAlgorithm");
}
}
示例7: generateParameters
import org.bouncycastle.crypto.digests.SHA256Digest; //导入依赖的package包/类
/**
* which generates the p and g values from the given parameters, returning
* the CramerShoupParameters object.
* <p>
* Note: can take a while...
* </p>
*/
public CramerShoupParameters generateParameters()
{
//
// find a safe prime p where p = 2*q + 1, where p and q are prime.
//
BigInteger[] safePrimes = ParametersHelper.generateSafePrimes(size, certainty, random);
// BigInteger p = safePrimes[0];
BigInteger q = safePrimes[1];
BigInteger g1 = ParametersHelper.selectGenerator(q, random);
BigInteger g2 = ParametersHelper.selectGenerator(q, random);
while (g1.equals(g2))
{
g2 = ParametersHelper.selectGenerator(q, random);
}
return new CramerShoupParameters(q, g1, g2, new SHA256Digest());
}
示例8: performTest
import org.bouncycastle.crypto.digests.SHA256Digest; //导入依赖的package包/类
public void performTest()
throws Exception
{
doExpectedTest(new SHA1Digest(), 0, expected0SHA1, noCycle0SHA1);
doExpectedTest(new SHA256Digest(), 0, expected0SHA256, noCycle0SHA256);
doExpectedTest(new SHA1Digest(), 100, expected100SHA1);
doExpectedTest(new SHA256Digest(), 100, expected100SHA256);
doExpectedTest(new SHA1Digest(), ZERO_SEED, expected0SHA1);
doExpectedTest(new SHA256Digest(), ZERO_SEED, expected0SHA256);
doExpectedTest(new SHA1Digest(), TEST_SEED, expectedTestSHA1);
doExpectedTest(new SHA256Digest(), TEST_SEED, expectedTestSHA256);
doCountTest(new SHA1Digest(), TEST_SEED, sha1Xors);
doCountTest(new SHA256Digest(), TEST_SEED, sha256Xors);
}
示例9: performTest
import org.bouncycastle.crypto.digests.SHA256Digest; //导入依赖的package包/类
public void performTest()
{
checkMask(1, new MGF1BytesGenerator(new ShortenedDigest(new SHA256Digest(), 20)), seed1, mask1);
checkMask(2, new MGF1BytesGenerator(new SHA1Digest()), seed2, mask2);
checkMask(3, new MGF1BytesGenerator(new ShortenedDigest(new SHA256Digest(), 20)), seed3, mask3);
try
{
new MGF1BytesGenerator(new SHA1Digest()).generateBytes(new byte[10], 0, 20);
fail("short input array not caught");
}
catch (DataLengthException e)
{
// expected
}
}
示例10: performTest
import org.bouncycastle.crypto.digests.SHA256Digest; //导入依赖的package包/类
public void performTest()
{
checkMask(1, new KDF1BytesGenerator(new ShortenedDigest(new SHA256Digest(), 20)), seed1, mask1);
checkMask(2, new KDF1BytesGenerator(new SHA1Digest()), seed2, mask2);
checkMask(3, new KDF1BytesGenerator(new ShortenedDigest(new SHA256Digest(), 20)), seed3, mask3);
try
{
new KDF1BytesGenerator(new SHA1Digest()).generateBytes(new byte[10], 0, 20);
fail("short input array not caught");
}
catch (DataLengthException e)
{
// expected
}
}
示例11: performTest
import org.bouncycastle.crypto.digests.SHA256Digest; //导入依赖的package包/类
public void performTest()
{
checkMask(1, new KDF2BytesGenerator(new ShortenedDigest(new SHA256Digest(), 20)), seed1, mask1);
checkMask(2, new KDF2BytesGenerator(new ShortenedDigest(new SHA256Digest(), 20)), seed2, mask2);
checkMask(3, new KDF2BytesGenerator(new SHA256Digest()), seed2, adjustedMask2);
checkMask(4, new KDF2BytesGenerator(new SHA1Digest()), seed2, sha1Mask);
checkMask(5, new KDF2BytesGenerator(new SHA1Digest()), seed3, mask3);
checkMask(6, new KDF2BytesGenerator(new SHA1Digest()), seed4, mask4);
try
{
new KDF2BytesGenerator(new SHA1Digest()).generateBytes(new byte[10], 0, 20);
fail("short input array not caught");
}
catch (DataLengthException e)
{
// expected
}
}
示例12: sign
import org.bouncycastle.crypto.digests.SHA256Digest; //导入依赖的package包/类
@Override
public byte[] sign(byte[] hash, byte[] privateKey) {
ECDSASigner signer = new ECDSASigner(new HMacDSAKCalculator(new SHA256Digest()));
signer.init(true, new ECPrivateKeyParameters(new BigInteger(privateKey), domain));
BigInteger[] signature = signer.generateSignature(hash);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
DERSequenceGenerator seq = new DERSequenceGenerator(baos);
seq.addObject(new ASN1Integer(signature[0]));
seq.addObject(new ASN1Integer(toCanonicalS(signature[1])));
seq.close();
return baos.toByteArray();
} catch (IOException e) {
return new byte[0];
}
}
示例13: decrypt
import org.bouncycastle.crypto.digests.SHA256Digest; //导入依赖的package包/类
/**
* A password-based data decryption using a constant salt value "<b>constantSalt</b>"
* @param cipher
* @param password
* @param salt
* @param iterationCount
* @return
* @throws Exception
*/
public static byte[] decrypt(byte[] cipher, String password) throws Exception
{
PKCS12ParametersGenerator pGen = new PKCS12ParametersGenerator(new SHA256Digest());
char[] passwordChars = password.toCharArray();
final byte[] pkcs12PasswordBytes = PBEParametersGenerator.PKCS12PasswordToBytes(passwordChars);
pGen.init(pkcs12PasswordBytes, constantSalt.getBytes(), iterations);
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;
}
示例14: calculateRounds
import org.bouncycastle.crypto.digests.SHA256Digest; //导入依赖的package包/类
public static int calculateRounds(int milliseconds)
{
Logging.info("Calculating how many SHA1 rounds we can do in %d millis.", milliseconds);
HMac mac = new HMac(new SHA256Digest());
byte[] state = new byte[mac.getMacSize()];
long startTime = System.currentTimeMillis();
int pbkdf2Iterations = 0;
while((System.currentTimeMillis() - startTime) < milliseconds)
{
mac.update(state, 0, state.length);
mac.doFinal(state, 0);
pbkdf2Iterations++;
}
pbkdf2Iterations = Math.max(pbkdf2Iterations, PBKDF2Descriptor.MINIMUM_PBKD2_ITERS);
Logging.info("Got %d", pbkdf2Iterations);
return pbkdf2Iterations;
}
示例15: decrypt
import org.bouncycastle.crypto.digests.SHA256Digest; //导入依赖的package包/类
static NSDictionary decrypt(BlobA6 blob, byte[] key) {
logger.debug("-- decrypt() - response blob: {}", blob);
byte[] pcsData = AESCBC.decryptAESCBC(key, blob.iv(), blob.data());
logger.debug("-- decrypt() - pcs data: 0x{}", Hex.toHexString(pcsData));
BlobA0 pcsBlob = new BlobA0(ByteBuffer.wrap(pcsData));
logger.debug("-- decrypt() - pcs blob: {}", pcsBlob);
byte[] derivedKey
= PBKDF2.generate(new SHA256Digest(), pcsBlob.dsid(), pcsBlob.salt(), pcsBlob.iterations(), 16 * 8);
logger.debug("-- decrypt() - derived key: 0x{}", Hex.toHexString(derivedKey));
byte[] saltIV = Arrays.copyOf(pcsBlob.salt(), 0x10);
logger.debug("-- decrypt() - salt/ iv: 0x{}", Hex.toHexString(saltIV));
byte[] dictionaryData = AESCBC.decryptAESCBC(derivedKey, saltIV, pcsBlob.data());
logger.debug("-- decrypt() - dictionary data: 0x{}", Hex.toHexString(dictionaryData));
NSDictionary dictionary = PListsLegacy.parseDictionary(dictionaryData);
logger.debug("-- decrypt() - dictionary: {}", dictionary.toXMLPropertyList());
return dictionary;
}