當前位置: 首頁>>代碼示例>>Java>>正文


Java SHA256Digest類代碼示例

本文整理匯總了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");
    }
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:21,代碼來源:TlsUtils.java

示例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");
    }
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:21,代碼來源:TlsUtils.java

示例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);
    }
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:22,代碼來源:DefaultTlsCipherFactory.java

示例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);
}
 
開發者ID:Appdome,項目名稱:ipack,代碼行數:20,代碼來源:JPAKEExample.java

示例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");
    }
}
 
開發者ID:ttt43ttt,項目名稱:gwt-crypto,代碼行數:21,代碼來源:TlsUtils.java

示例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");
    }
}
 
開發者ID:ttt43ttt,項目名稱:gwt-crypto,代碼行數:21,代碼來源:TlsUtils.java

示例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());
    }
 
開發者ID:ttt43ttt,項目名稱:gwt-crypto,代碼行數:26,代碼來源:CramerShoupParametersGenerator.java

示例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);
}
 
開發者ID:ttt43ttt,項目名稱:gwt-crypto,代碼行數:19,代碼來源:DigestRandomNumberTest.java

示例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 
    }
}
 
開發者ID:ttt43ttt,項目名稱:gwt-crypto,代碼行數:18,代碼來源:MGF1GeneratorTest.java

示例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 
    }
}
 
開發者ID:ttt43ttt,項目名稱:gwt-crypto,代碼行數:18,代碼來源:KDF1GeneratorTest.java

示例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 
    }
}
 
開發者ID:ttt43ttt,項目名稱:gwt-crypto,代碼行數:21,代碼來源:KDF2GeneratorTest.java

示例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];
    }
}
 
開發者ID:hyperledger-archives,項目名稱:fabric-api-archive,代碼行數:17,代碼來源:BouncyCastleCrypto.java

示例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;
}
 
開發者ID:giuseppeurso-eu,項目名稱:java-security,代碼行數:27,代碼來源:PasswordBasedEncryption.java

示例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;
}
 
開發者ID:AstromechZA,項目名稱:bunkr,代碼行數:18,代碼來源:PBKDF2Descriptor.java

示例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;
}
 
開發者ID:horrorho,項目名稱:InflatableDonkey,代碼行數:24,代碼來源:EscrowOperationsRecover.java


注:本文中的org.bouncycastle.crypto.digests.SHA256Digest類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。