当前位置: 首页>>代码示例>>Java>>正文


Java SHA256Digest类代码示例

本文整理汇总了Java中org.spongycastle.crypto.digests.SHA256Digest的典型用法代码示例。如果您正苦于以下问题:Java SHA256Digest类的具体用法?Java SHA256Digest怎么用?Java SHA256Digest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SHA256Digest类属于org.spongycastle.crypto.digests包,在下文中一共展示了SHA256Digest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doSign

import org.spongycastle.crypto.digests.SHA256Digest; //导入依赖的package包/类
/**
 * Signs the given hash and returns the R and S components as BigIntegers
 * and put them in ECDSASignature
 *
 * @param input to sign
 * @return ECDSASignature signature that contains the R and S components
 */
public ECDSASignature doSign(byte[] input) {
    if (input.length != 32) {
        throw new IllegalArgumentException("Expected 32 byte input to ECDSA signature, not " + input.length);
    }
    // No decryption of private key required.
    if (privKey == null)
        throw new MissingPrivateKeyException();
    if (privKey instanceof BCECPrivateKey) {
        ECDSASigner signer = new ECDSASigner(new HMacDSAKCalculator(new SHA256Digest()));
        ECPrivateKeyParameters privKeyParams = new ECPrivateKeyParameters(((BCECPrivateKey) privKey).getD(), CURVE);
        signer.init(true, privKeyParams);
        BigInteger[] components = signer.generateSignature(input);
        return new ECDSASignature(components[0], components[1]).toCanonicalised();
    } else {
        try {
            final Signature ecSig = ECSignatureFactory.getRawInstance(provider);
            ecSig.initSign(privKey);
            ecSig.update(input);
            final byte[] derSignature = ecSig.sign();
            return ECDSASignature.decodeFromDER(derSignature).toCanonicalised();
        } catch (SignatureException | InvalidKeyException ex) {
            throw new RuntimeException("ECKey signing error", ex);
        }
    }
}
 
开发者ID:Aptoide,项目名称:AppCoins-ethereumj,代码行数:33,代码来源:ECKey.java

示例2: decrypt

import org.spongycastle.crypto.digests.SHA256Digest; //导入依赖的package包/类
public static byte[] decrypt(ECPoint ephem, BigInteger prv, byte[] IV, byte[] cipher, byte[] macData) throws InvalidCipherTextException {
    AESFastEngine aesFastEngine = new AESFastEngine();

    EthereumIESEngine iesEngine = new EthereumIESEngine(
            new ECDHBasicAgreement(),
            new ConcatKDFBytesGenerator(new SHA256Digest()),
            new HMac(new SHA256Digest()),
            new SHA256Digest(),
            new BufferedBlockCipher(new SICBlockCipher(aesFastEngine)));


    byte[]         d = new byte[] {};
    byte[]         e = new byte[] {};

    IESParameters p = new IESWithCipherParameters(d, e, KEY_SIZE, KEY_SIZE);
    ParametersWithIV parametersWithIV =
            new ParametersWithIV(p, IV);

    iesEngine.init(false, new ECPrivateKeyParameters(prv, CURVE), new ECPublicKeyParameters(ephem, CURVE), parametersWithIV);

    return iesEngine.processBlock(cipher, 0, cipher.length, macData);
}
 
开发者ID:talentchain,项目名称:talchain,代码行数:23,代码来源:ECIESCoder.java

示例3: makeIESEngine

import org.spongycastle.crypto.digests.SHA256Digest; //导入依赖的package包/类
private static EthereumIESEngine makeIESEngine(boolean isEncrypt, ECPoint pub, BigInteger prv, byte[] IV) {
    AESFastEngine aesFastEngine = new AESFastEngine();

    EthereumIESEngine iesEngine = new EthereumIESEngine(
            new ECDHBasicAgreement(),
            new ConcatKDFBytesGenerator(new SHA256Digest()),
            new HMac(new SHA256Digest()),
            new SHA256Digest(),
            new BufferedBlockCipher(new SICBlockCipher(aesFastEngine)));


    byte[]         d = new byte[] {};
    byte[]         e = new byte[] {};

    IESParameters p = new IESWithCipherParameters(d, e, KEY_SIZE, KEY_SIZE);
    ParametersWithIV parametersWithIV = new ParametersWithIV(p, IV);

    iesEngine.init(isEncrypt, new ECPrivateKeyParameters(prv, CURVE), new ECPublicKeyParameters(pub, CURVE), parametersWithIV);
    return iesEngine;
}
 
开发者ID:talentchain,项目名称:talchain,代码行数:21,代码来源:ECIESCoder.java

示例4: makeIESEngine

import org.spongycastle.crypto.digests.SHA256Digest; //导入依赖的package包/类
private static EthereumIESEngine makeIESEngine(boolean isEncrypt, ECPoint pub, BigInteger prv, byte[] IV) {
    AESFastEngine aesFastEngine = new AESFastEngine();

    EthereumIESEngine iesEngine = new EthereumIESEngine(
            new ECDHBasicAgreement(),
            new ConcatKDFBytesGenerator(new SHA256Digest()),
            new HMac(new SHA256Digest()),
            new SHA256Digest(),
            new BufferedBlockCipher(new SICBlockCipher(aesFastEngine)));


    byte[]         d = new byte[] {};
    byte[]         e = new byte[] {};

    IESParameters p = new IESWithCipherParameters(d, e, KEY_SIZE, KEY_SIZE);
    ParametersWithIV parametersWithIV = new ParametersWithIV(p, IV);

    iesEngine.init(isEncrypt, new ECPrivateKeyParameters(prv, curve), new ECPublicKeyParameters(pub, curve), parametersWithIV);
    return iesEngine;
}
 
开发者ID:talentchain,项目名称:talchain,代码行数:21,代码来源:ECIESTest.java

示例5: compressCoinbase

import org.spongycastle.crypto.digests.SHA256Digest; //导入依赖的package包/类
public static byte[] compressCoinbase(byte[] bitcoinMergedMiningCoinbaseTransactionSerialized, boolean lastOcurrence) {
    List<Byte> coinBaseTransactionSerializedAsList = java.util.Arrays.asList(ArrayUtils.toObject(bitcoinMergedMiningCoinbaseTransactionSerialized));
    List<Byte> tagAsList = java.util.Arrays.asList(ArrayUtils.toObject(RskMiningConstants.RSK_TAG));

    int rskTagPosition;
    if (lastOcurrence) {
        rskTagPosition = Collections.lastIndexOfSubList(coinBaseTransactionSerializedAsList, tagAsList);
    } else {
        rskTagPosition = Collections.indexOfSubList(coinBaseTransactionSerializedAsList, tagAsList);
    }

    int remainingByteCount = bitcoinMergedMiningCoinbaseTransactionSerialized.length - rskTagPosition - RskMiningConstants.RSK_TAG.length - RskMiningConstants.BLOCK_HEADER_HASH_SIZE;
    if (remainingByteCount > RskMiningConstants.MAX_BYTES_AFTER_MERGED_MINING_HASH) {
        throw new IllegalArgumentException("More than 128 bytes after RSK tag");
    }
    int sha256Blocks = rskTagPosition / 64;
    int bytesToHash = sha256Blocks * 64;
    SHA256Digest digest = new SHA256Digest();
    digest.update(bitcoinMergedMiningCoinbaseTransactionSerialized, 0, bytesToHash);
    byte[] hashedContent = digest.getEncodedState();
    byte[] trimmedHashedContent = new byte[RskMiningConstants.MIDSTATE_SIZE_TRIMMED];
    System.arraycopy(hashedContent, 8, trimmedHashedContent, 0, RskMiningConstants.MIDSTATE_SIZE_TRIMMED);
    byte[] unHashedContent = new byte[bitcoinMergedMiningCoinbaseTransactionSerialized.length - bytesToHash];
    System.arraycopy(bitcoinMergedMiningCoinbaseTransactionSerialized, bytesToHash, unHashedContent, 0, unHashedContent.length);
    return Arrays.concatenate(trimmedHashedContent, unHashedContent);
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:27,代码来源:MinerServerImpl.java

示例6: decrypt

import org.spongycastle.crypto.digests.SHA256Digest; //导入依赖的package包/类
public static byte[] decrypt(ECPoint ephem, BigInteger prv, byte[] iv, byte[] cipher, byte[] macData) throws InvalidCipherTextException {
    AESFastEngine aesFastEngine = new AESFastEngine();

    EthereumIESEngine iesEngine = new EthereumIESEngine(
            new ECDHBasicAgreement(),
            new ConcatKDFBytesGenerator(new SHA256Digest()),
            new HMac(new SHA256Digest()),
            new SHA256Digest(),
            new BufferedBlockCipher(new SICBlockCipher(aesFastEngine)));


    byte[]         d = new byte[] {};
    byte[]         e = new byte[] {};

    IESParameters p = new IESWithCipherParameters(d, e, KEY_SIZE, KEY_SIZE);
    ParametersWithIV parametersWithIV =
            new ParametersWithIV(p, iv);

    iesEngine.init(false, new ECPrivateKeyParameters(prv, CURVE), new ECPublicKeyParameters(ephem, CURVE), parametersWithIV);

    return iesEngine.processBlock(cipher, 0, cipher.length, macData);
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:23,代码来源:ECIESCoder.java

示例7: makeIESEngine

import org.spongycastle.crypto.digests.SHA256Digest; //导入依赖的package包/类
private static EthereumIESEngine makeIESEngine(boolean isEncrypt, ECPoint pub, BigInteger prv, byte[] iv) {
    AESFastEngine aesFastEngine = new AESFastEngine();

    EthereumIESEngine iesEngine = new EthereumIESEngine(
            new ECDHBasicAgreement(),
            new ConcatKDFBytesGenerator(new SHA256Digest()),
            new HMac(new SHA256Digest()),
            new SHA256Digest(),
            new BufferedBlockCipher(new SICBlockCipher(aesFastEngine)));


    byte[]         d = new byte[] {};
    byte[]         e = new byte[] {};

    IESParameters p = new IESWithCipherParameters(d, e, KEY_SIZE, KEY_SIZE);
    ParametersWithIV parametersWithIV = new ParametersWithIV(p, iv);

    iesEngine.init(isEncrypt, new ECPrivateKeyParameters(prv, CURVE), new ECPublicKeyParameters(pub, CURVE), parametersWithIV);
    return iesEngine;
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:21,代码来源:ECIESCoder.java

示例8: doSign

import org.spongycastle.crypto.digests.SHA256Digest; //导入依赖的package包/类
protected ECDSASignature doSign(Sha256Hash input, BigInteger privateKeyForSigning) {
    if (Secp256k1Context.isEnabled()) {
        try {
            byte[] signature = NativeSecp256k1.sign(
                    input.getBytes(),
                    Utils.bigIntegerToBytes(privateKeyForSigning, 32)
            );
            return ECDSASignature.decodeFromDER(signature);
        } catch (NativeSecp256k1Util.AssertFailException e) {
            log.error("Caught AssertFailException inside secp256k1", e);
            throw new RuntimeException(e);
        }
    }
    if (FAKE_SIGNATURES)
        return TransactionSignature.dummy();
    checkNotNull(privateKeyForSigning);
    ECDSASigner signer = new ECDSASigner(new HMacDSAKCalculator(new SHA256Digest()));
    ECPrivateKeyParameters privKey = new ECPrivateKeyParameters(privateKeyForSigning, CURVE);
    signer.init(true, privKey);
    BigInteger[] components = signer.generateSignature(input.getBytes());
    return new ECDSASignature(components[0], components[1]).toCanonicalised();
}
 
开发者ID:creativechain,项目名称:creacoinj,代码行数:23,代码来源:ECKey.java

示例9: doSign

import org.spongycastle.crypto.digests.SHA256Digest; //导入依赖的package包/类
protected ECDSASignature doSign(Sha256Hash input, BigInteger privateKeyForSigning) {
    if (Secp256k1Context.isEnabled()) {
        try {
            byte[] signature = NativeSecp256k1.sign(input.getBytes(),
                    CryptoUtils.bigIntegerToBytes(privateKeyForSigning, 32));
            return ECDSASignature.decodeFromDER(signature);
        } catch (NativeSecp256k1Util.AssertFailException e) {
            log.error("Caught AssertFailException inside secp256k1", e);
            throw new RuntimeException(e);
        }
    }
    if (FAKE_SIGNATURES)
        // return TransactionSignature.dummy();
        checkNotNull(privateKeyForSigning);
    ECDSASigner signer = new ECDSASigner(new HMacDSAKCalculator(new SHA256Digest()));
    ECPrivateKeyParameters privKey = new ECPrivateKeyParameters(privateKeyForSigning, CURVE);
    signer.init(true, privKey);
    BigInteger[] components = signer.generateSignature(input.getBytes());
    return new ECDSASignature(components[0], components[1]).toCanonicalised();
}
 
开发者ID:marvin-we,项目名称:crypto-core,代码行数:21,代码来源:ECKey.java

示例10: getDigest

import org.spongycastle.crypto.digests.SHA256Digest; //导入依赖的package包/类
public static Digest getDigest(HashAlgorithmTypes shaType) {


        if (shaType.equals(HashAlgorithmTypes.SHA_1)) {
            return new SHA1Digest();
        }
        if (shaType.equals(HashAlgorithmTypes.MD_5)) {
            return new MD5Digest();
        }
        if (shaType.equals(HashAlgorithmTypes.SHA_256)) {
            return new SHA256Digest();
        }
        if (shaType.equals(HashAlgorithmTypes.SHA_384)) {
            return new SHA384Digest();
        }
        if (shaType.equals(HashAlgorithmTypes.SHA_512)) {
            return new SHA512Digest();
        }
        return null;
    }
 
开发者ID:roman-smirnov,项目名称:CryptoBox,代码行数:21,代码来源:DigestFactory.java

示例11: createCipher

import org.spongycastle.crypto.digests.SHA256Digest; //导入依赖的package包/类
protected PaddedBufferedBlockCipher createCipher(String passphrase, boolean isEncrypting) throws CryptoException{
	CustomRandom cRandom = new CustomRandom(utf8Bytes(passphrase));
	byte[] salt = new byte[8];
	cRandom.nextBytes(salt);
	byte[] password = new byte[32];
	cRandom.nextBytes(password);
	int iterationCount = 1000;
	int keyLength = 256;		
	int blockSize = 128;
	
	PKCS5S2ParametersGenerator generator = new PKCS5S2ParametersGenerator(new SHA256Digest());
	generator.init(password, salt, iterationCount);

	CipherParameters key = generator
				.generateDerivedParameters(keyLength, blockSize);
	
	CBCBlockCipher cbcCipher = new CBCBlockCipher(new AESEngine());
	PaddedBufferedBlockCipher cipher = new PaddedBufferedBlockCipher(
			cbcCipher, new PKCS7Padding());
	cipher.init(isEncrypting, key);
	return cipher;
}
 
开发者ID:micheal-swiggs,项目名称:jumblar,代码行数:23,代码来源:WeakSymmetricEncryption.java

示例12: createKey

import org.spongycastle.crypto.digests.SHA256Digest; //导入依赖的package包/类
private KeyParameter createKey(String password, byte[] salt,
		int iterations, int keySizeInBits) {
	//System.out.println(keySizeInBits);
	//System.out.println(iterations);
	//System.out.println(salt);
	//System.out.println(password);
	
	PKCS5S2ParametersGenerator generator = new PKCS5S2ParametersGenerator(
			new SHA256Digest());
	generator.init(
			PBEParametersGenerator.PKCS5PasswordToUTF8Bytes(password.toCharArray()), 
			salt, 
			iterations);
	KeyParameter key = (KeyParameter) generator
			.generateDerivedMacParameters(keySizeInBits);
	return key;
}
 
开发者ID:AurionFinancial,项目名称:AndroidWallet,代码行数:18,代码来源:Blobvault.java

示例13: testKDF

import org.spongycastle.crypto.digests.SHA256Digest; //导入依赖的package包/类
@Test
public void testKDF() {
    ConcatKDFBytesGenerator kdf = new ConcatKDFBytesGenerator(new SHA256Digest());
    kdf.init(new KDFParameters("Hello".getBytes(), new byte[0]));
    byte[] bytes = new byte[2];
    kdf.generateBytes(bytes, 0, bytes.length);
    assertArrayEquals(new byte[]{-66, -89}, bytes);
}
 
开发者ID:talentchain,项目名称:talchain,代码行数:9,代码来源:ECIESTest.java

示例14: pbkdf2

import org.spongycastle.crypto.digests.SHA256Digest; //导入依赖的package包/类
private byte[] pbkdf2(String password, byte[] salt, int iterations) {
	byte[] utf8 = StringUtils.toUtf8(password);
	Digest digest = new SHA256Digest();
	PKCS5S2ParametersGenerator gen = new PKCS5S2ParametersGenerator(digest);
	gen.init(utf8, salt, iterations);
	int keyLengthInBits = SecretKey.LENGTH * 8;
	CipherParameters p = gen.generateDerivedParameters(keyLengthInBits);
	return ((KeyParameter) p).getKey();
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:10,代码来源:CryptoComponentImpl.java

示例15: sampleRunningTime

import org.spongycastle.crypto.digests.SHA256Digest; //导入依赖的package包/类
private long sampleRunningTime(int iterations) {
	byte[] password = {'p', 'a', 's', 's', 'w', 'o', 'r', 'd'};
	byte[] salt = new byte[PBKDF_SALT_BYTES];
	int keyLengthInBits = SecretKey.LENGTH * 8;
	long start = System.nanoTime();
	Digest digest = new SHA256Digest();
	PKCS5S2ParametersGenerator gen = new PKCS5S2ParametersGenerator(digest);
	gen.init(password, salt, iterations);
	gen.generateDerivedParameters(keyLengthInBits);
	return System.nanoTime() - start;
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:12,代码来源:CryptoComponentImpl.java


注:本文中的org.spongycastle.crypto.digests.SHA256Digest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。