• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java KeccakDigest类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: performTest

import org.bouncycastle.crypto.digests.KeccakDigest; //导入依赖的package包/类
public void performTest() throws Exception
{
    testDigest(new KeccakDigest(), digests288);
    testDigest(new KeccakDigest(224), digests224);
    testDigest(new KeccakDigest(256), digests256);
    testDigest(new KeccakDigest(384), digests384);
    testDigest(new KeccakDigest(512), digests512);

    testMac(new KeccakDigest(224), macKeys, macData, mac224, trunc224);
    testMac(new KeccakDigest(256), macKeys, macData, mac256, trunc256);
    testMac(new KeccakDigest(384), macKeys, macData, mac384, trunc384);
    testMac(new KeccakDigest(512), macKeys, macData, mac512, trunc512);
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:14,代码来源:KeccakDigestTest.java


示例2: initDigesters

import org.bouncycastle.crypto.digests.KeccakDigest; //导入依赖的package包/类
private static void initDigesters() {
	digesters.put("Blake2b", Blake2bDigest.class);
	digesters.put("GOST3411", GOST3411Digest.class);
	digesters.put("Keccak", KeccakDigest.class);
	digesters.put("MD2", MD2Digest.class);
	digesters.put("MD4", MD4Digest.class);
	digesters.put("MD5", MD5Digest.class);
	digesters.put("RIPEMD128", RIPEMD128Digest.class);
	digesters.put("RIPEMD160", RIPEMD160Digest.class);
	digesters.put("RIPEMD256", RIPEMD256Digest.class);
	digesters.put("RIPEMD320", RIPEMD320Digest.class);
	digesters.put("SHA1", SHA1Digest.class);
	digesters.put("SHA224", SHA224Digest.class);
	digesters.put("SHA256", SHA256Digest.class);
	digesters.put("SHA384", SHA384Digest.class);
	digesters.put("SHA3-512", SHA3Digest.class);
	digesters.put("SHA3-256", SHA3Digest.class);
	digesters.put("SHA3-224", SHA3Digest.class);
	digesters.put("SHA3-384", SHA3Digest.class);
	digesters.put("SHA512", SHA512Digest.class);
	digesters.put("SHAKE-128", SHAKEDigest.class);
	digesters.put("SHAKE-256", SHAKEDigest.class);
	digesters.put("Skein256", SkeinDigest.class);
	digesters.put("Skein512", SkeinDigest.class);
	digesters.put("Skein1024", SkeinDigest.class);
	digesters.put("SM3", SM3Digest.class);
	digesters.put("Tiger", TigerDigest.class);
	digesters.put("Whirlpool", WhirlpoolDigest.class);
}
 
开发者ID:shilongdai,项目名称:vsDiaryWriter,代码行数:30,代码来源:Digesters.java


示例3: clone

import org.bouncycastle.crypto.digests.KeccakDigest; //导入依赖的package包/类
public Object clone()
    throws CloneNotSupportedException
{
    BCMessageDigest d = (BCMessageDigest)super.clone();
    d.digest = new KeccakDigest((KeccakDigest)digest);

    return d;
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:9,代码来源:Keccak.java


示例4: cloneDigest

import org.bouncycastle.crypto.digests.KeccakDigest; //导入依赖的package包/类
protected Digest cloneDigest(Digest digest)
{
    return new KeccakDigest((KeccakDigest)digest);
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:5,代码来源:KeccakDigestTest.java


示例5: createWallet

import org.bouncycastle.crypto.digests.KeccakDigest; //导入依赖的package包/类
/**
 * Create a random wallet (new keys pairs).
 *
 * @param passphrase to encrypt private key with
 * @return storage
 */
public static WalletStoragePojoV3 createWallet(String passphrase) {
    WalletStoragePojoV3 wallet = new WalletStoragePojoV3();
    wallet.version = STORAGE_VERSION;
    wallet.id = UUID.randomUUID().toString();

    ECKey ecdsaPair = new ECKey();

    try {
        wallet.address = CryptoUtil.byteToHex(ecdsaPair.getAddress());

        WalletCryptoPojoV3 crypto = new WalletCryptoPojoV3();
        wallet.crypto = crypto;
        crypto.setCipher(CIPHER);

        // create key to crypt private key with AES
        // key will be a derived hash

        byte[] saltBytes = new byte[32];
        Random saltRandom = new Random();
        saltRandom.nextBytes(saltBytes);
        String salt = CryptoUtil.byteToHex(saltBytes);

        crypto.setKdf(KDF);
        crypto.getKdfparams().setSalt(salt);
        crypto.getKdfparams().setDklen(DKLEN);
        crypto.getKdfparams().setPrf(PRF);
        crypto.getKdfparams().setC(ITERATIONS);

        byte[] key = Pbkdf2.derive(passphrase, saltBytes, crypto.getKdfparams().getC(), crypto.getKdfparams().getDklen());

        // select AES algorithm
        Cipher cipher = Cipher.getInstance("AES/CTR/NoPadding");

        // key will only be the first 16 bytes of the hash key
        byte[] trimmedKey = Arrays.copyOfRange(key, 0, 16);

        // macKey that will be used to validate wallet unlocking (as per
        // ethereum standard)
        byte[] macKey = Arrays.copyOfRange(key, 16, 32);

        // crypt using AES and get generated IV
        SecretKeySpec secretKeySpec = new SecretKeySpec(trimmedKey, "AES");
        cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec);
        byte[] privateKeyBytes = ecdsaPair.getPrivKeyBytes();
        byte[] ciphertext = cipher.doFinal(privateKeyBytes);

        // generate MAC as per ethereum standard
        KeccakDigest md = new KeccakDigest(256);
        byte[] macSource = new byte[macKey.length + ciphertext.length];
        System.arraycopy(macKey, 0, macSource, 0, macKey.length);
        System.arraycopy(ciphertext, 0, macSource, macKey.length, ciphertext.length);

        md.update(macSource, 0, macSource.length);
        byte[] mac = new byte[md.getDigestSize()];
        md.doFinal(mac, 0);

        // set in storage
        crypto.setMac(CryptoUtil.byteToHex(mac));
        byte[] iv = cipher.getIV();
        crypto.getCipherparams().setIv(CryptoUtil.byteToHex(iv));
        crypto.setCiphertext(CryptoUtil.byteToHex(ciphertext));

    } catch (Exception ex) {
        ex.printStackTrace();
    }

    return wallet;
}
 
开发者ID:cegeka,项目名称:tether,代码行数:75,代码来源:WalletStoragePojoV3.java


示例6: getPrivateKey

import org.bouncycastle.crypto.digests.KeccakDigest; //导入依赖的package包/类
/**
 * Decrypt private key.
 *
 * @param passphrase to decrypt
 * @return private key data
 */
public byte[] getPrivateKey(String passphrase) {
    if (crypto.getCipher().equals(CIPHER) && crypto.getKdf().equals(KDF)) {
        byte[] key = Pbkdf2.derive(passphrase, CryptoUtil.hexToBytes(crypto.getKdfparams().getSalt()),
                crypto.getKdfparams().getC(), crypto.getKdfparams().getDklen());
        try {
            // macKey that will be used to validate wallet unlocking (as per
            // ethereum standard)
            byte[] macKey = Arrays.copyOfRange(key, 16, 32);

            byte[] ciphertext = CryptoUtil.hexToBytes(crypto.getCiphertext());
            // generate MAC as per ethereum standard
            KeccakDigest md = new KeccakDigest(256);
            byte[] macSource = new byte[macKey.length + ciphertext.length];
            System.arraycopy(macKey, 0, macSource, 0, macKey.length);
            System.arraycopy(ciphertext, 0, macSource, macKey.length, ciphertext.length);

            md.update(macSource, 0, macSource.length);
            byte[] mac = new byte[md.getDigestSize()];
            md.doFinal(mac, 0);

            if (!CryptoUtil.byteToHex(mac).equals(crypto.getMac())) {
                // MAC MISMATCH
                return null;
            }

            // key will only be the first 16 bytes of the hash key
            byte[] trimmedKey = Arrays.copyOfRange(key, 0, 16);
            SecretKeySpec secretKeySpec = new SecretKeySpec(trimmedKey, "AES");
            byte[] ivAsBytes = CryptoUtil.hexToBytes(crypto.getCipherparams().getIv());
            IvParameterSpec iv = new IvParameterSpec(ivAsBytes);

            Cipher cipher = Cipher.getInstance("AES/CTR/NoPadding");
            cipher.init(Cipher.DECRYPT_MODE, secretKeySpec, iv);
            byte[] privateKey = cipher.doFinal(CryptoUtil.hexToBytes(crypto.getCiphertext()));

            return privateKey;

        } catch (Exception ex) {
            ex.printStackTrace();
        }
    } else {
        throw new UnsupportedOperationException("Wallet is incompatible or corrupted!");
    }

    return null;
}
 
开发者ID:cegeka,项目名称:tether,代码行数:53,代码来源:WalletStoragePojoV3.java


示例7: DigestKeccak

import org.bouncycastle.crypto.digests.KeccakDigest; //导入依赖的package包/类
public DigestKeccak(int size)
{
    super(new KeccakDigest(size));
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:5,代码来源:Keccak.java


示例8: HashMac224

import org.bouncycastle.crypto.digests.KeccakDigest; //导入依赖的package包/类
public HashMac224()
{
    super(new HMac(new KeccakDigest(224)));
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:5,代码来源:Keccak.java


示例9: HashMac256

import org.bouncycastle.crypto.digests.KeccakDigest; //导入依赖的package包/类
public HashMac256()
{
    super(new HMac(new KeccakDigest(256)));
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:5,代码来源:Keccak.java


示例10: HashMac288

import org.bouncycastle.crypto.digests.KeccakDigest; //导入依赖的package包/类
public HashMac288()
{
    super(new HMac(new KeccakDigest(288)));
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:5,代码来源:Keccak.java


示例11: HashMac384

import org.bouncycastle.crypto.digests.KeccakDigest; //导入依赖的package包/类
public HashMac384()
{
    super(new HMac(new KeccakDigest(384)));
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:5,代码来源:Keccak.java


示例12: HashMac512

import org.bouncycastle.crypto.digests.KeccakDigest; //导入依赖的package包/类
public HashMac512()
{
    super(new HMac(new KeccakDigest(512)));
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:5,代码来源:Keccak.java


示例13: createECDSASigner

import org.bouncycastle.crypto.digests.KeccakDigest; //导入依赖的package包/类
private ECDSASigner createECDSASigner() {
	return new ECDSASigner(new HMacDSAKCalculator(new KeccakDigest(256)));
}
 
开发者ID:NemProject,项目名称:nem.core,代码行数:4,代码来源:SecP256K1DsaSigner.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java BootstrapResolver类代码示例发布时间:2022-05-23
下一篇:
Java ReorientReferenceRelationshipRequest类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap