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

Java Wrapper类代码示例

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

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



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

示例1: createRFC3211Wrapper

import org.bouncycastle.crypto.Wrapper; //导入依赖的package包/类
static Wrapper createRFC3211Wrapper(ASN1ObjectIdentifier algorithm)
    throws CMSException
{
    if (NISTObjectIdentifiers.id_aes128_CBC.equals(algorithm)
        || NISTObjectIdentifiers.id_aes192_CBC.equals(algorithm)
        || NISTObjectIdentifiers.id_aes256_CBC.equals(algorithm))
    {
        return new RFC3211WrapEngine(new AESEngine());
    }
    else if (PKCSObjectIdentifiers.des_EDE3_CBC.equals(algorithm))
    {
        return new RFC3211WrapEngine(new DESedeEngine());
    }
    else if (OIWObjectIdentifiers.desCBC.equals(algorithm))
    {
        return new RFC3211WrapEngine(new DESEngine());
    }
    else if (PKCSObjectIdentifiers.RC2_CBC.equals(algorithm))
    {
        return new RFC3211WrapEngine(new RC2Engine());
    }
    else
    {
        throw new CMSException("cannot recognise wrapper: " + algorithm);
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:27,代码来源:EnvelopedDataHelper.java


示例2: extractSecretKey

import org.bouncycastle.crypto.Wrapper; //导入依赖的package包/类
protected KeyParameter extractSecretKey(AlgorithmIdentifier keyEncryptionAlgorithm, AlgorithmIdentifier contentEncryptionAlgorithm, byte[] derivedKey, byte[] encryptedContentEncryptionKey)
    throws CMSException
{
    Wrapper keyEncryptionCipher = EnvelopedDataHelper.createRFC3211Wrapper(keyEncryptionAlgorithm.getAlgorithm());

    keyEncryptionCipher.init(false, new ParametersWithIV(new KeyParameter(derivedKey), ASN1OctetString.getInstance(keyEncryptionAlgorithm.getParameters()).getOctets()));

    try
    {
        return new KeyParameter(keyEncryptionCipher.unwrap(encryptedContentEncryptionKey, 0, encryptedContentEncryptionKey.length));
    }
    catch (InvalidCipherTextException e)
    {
        throw new CMSException("unable to unwrap key: " + e.getMessage(), e);
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:17,代码来源:BcPasswordRecipient.java


示例3: createWrapper

import org.bouncycastle.crypto.Wrapper; //导入依赖的package包/类
static Wrapper createWrapper(int encAlgorithm)
    throws PGPException
{
    switch (encAlgorithm)
    {
    case SymmetricKeyAlgorithmTags.AES_128:
    case SymmetricKeyAlgorithmTags.AES_192:
    case SymmetricKeyAlgorithmTags.AES_256:
        return new RFC3394WrapEngine(new AESFastEngine());
    case SymmetricKeyAlgorithmTags.CAMELLIA_128:
    case SymmetricKeyAlgorithmTags.CAMELLIA_192:
    case SymmetricKeyAlgorithmTags.CAMELLIA_256:
        return new RFC3394WrapEngine(new CamelliaEngine());
    default:
        throw new PGPException("unknown wrap algorithm: " + encAlgorithm);
    }
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:18,代码来源:BcImplProvider.java


示例4: wrapAndUnwrap

import org.bouncycastle.crypto.Wrapper; //导入依赖的package包/类
private void wrapAndUnwrap(byte[] kek, byte[] key, byte[] expected)
    throws Exception
{
    Wrapper wrapper = new AESWrapPadEngine();

    wrapper.init(true, new KeyParameter(kek));

    byte[] cipherText = wrapper.wrap(key, 0, key.length);
    if (!areEqual(cipherText, expected))
    {
        fail("Wrapped value does not match expected.");
    }
    wrapper.init(false, new KeyParameter(kek));
    byte[] plainText = wrapper.unwrap(cipherText, 0, cipherText.length);

    if (!areEqual(key, plainText))
    {
        fail("Unwrapped value does not match original.");
    }
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:21,代码来源:AESWrapPadTest.java


示例5: heapIssueTest

import org.bouncycastle.crypto.Wrapper; //导入依赖的package包/类
private void heapIssueTest()
{
	byte[] key = Hex.decode("d305ef52a6b9e72c810b821261d2d678");
	byte[] ciphertext = Hex.decode("d2b2906d209a46261d8f6794eca3179d");

	Wrapper aes = new AESWrapPadEngine();
	aes.init(false, new KeyParameter(key));
    try
    {
        byte[] result = aes.unwrap(ciphertext, 0, ciphertext.length);

        fail("incorrect pad not detected");
    }
    catch (InvalidCipherTextException e)
    {
        // ignore
    }
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:19,代码来源:AESWrapTest.java


示例6: testChecksum

import org.bouncycastle.crypto.Wrapper; //导入依赖的package包/类
private void testChecksum(byte[] kek, byte[] iv, byte[] block, Wrapper wrapper)
{
    encryptBlock(kek, iv, block);

    try
    {
        wrapper.unwrap(block, 0, block.length);

        fail("bad checksum not detected");
    }
    catch (InvalidCipherTextException e)
    {
        if (!e.getMessage().equals("wrapped key fails checksum"))
        {
            fail("wrong exception");
        }
    }
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:19,代码来源:RFC3211WrapTest.java


示例7: create

import org.bouncycastle.crypto.Wrapper; //导入依赖的package包/类
private static RFC6637 create(
        String curveName,
        Supplier<Digest> digestFactory,
        Supplier<Wrapper> wrapperFactory,
        int publicKeyAlgID,
        int symAlgID,
        int symAlgIDLength,
        int kdfHashID) {

    try {
        ASN1ObjectIdentifier oid = ECNamedCurveTable.getOID(curveName);

        RFC6637KDF kdf = new RFC6637KDF(
                digestFactory,
                oid,
                (byte) publicKeyAlgID,
                (byte) symAlgID,
                (byte) kdfHashID);

        return new RFC6637(wrapperFactory, curveName, symAlgIDLength, kdf);

    } catch (IOException ex) {
        throw new IllegalStateException(ex);
    }
}
 
开发者ID:horrorho,项目名称:InflatableDonkey,代码行数:26,代码来源:RFC6637Factory.java


示例8: WrapCipherSpi

import org.bouncycastle.crypto.Wrapper; //导入依赖的package包/类
protected WrapCipherSpi(
    Wrapper wrapEngine,
    int     ivSize)
{
    this.wrapEngine = wrapEngine;
    this.ivSize = ivSize;
}
 
开发者ID:PhilippC,项目名称:keepass2android,代码行数:8,代码来源:WrapCipherSpi.java


示例9: BcSymmetricKeyUnwrapper

import org.bouncycastle.crypto.Wrapper; //导入依赖的package包/类
public BcSymmetricKeyUnwrapper(AlgorithmIdentifier wrappingAlgorithm, Wrapper wrapper, KeyParameter wrappingKey)
{
    super(wrappingAlgorithm);

    this.wrapper = wrapper;
    this.wrappingKey = wrappingKey;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:8,代码来源:BcSymmetricKeyUnwrapper.java


示例10: BcSymmetricKeyWrapper

import org.bouncycastle.crypto.Wrapper; //导入依赖的package包/类
public BcSymmetricKeyWrapper(AlgorithmIdentifier wrappingAlgorithm, Wrapper wrapper, KeyParameter wrappingKey)
{
    super(wrappingAlgorithm);

    this.wrapper = wrapper;
    this.wrappingKey = wrappingKey;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:8,代码来源:BcSymmetricKeyWrapper.java


示例11: BaseWrapCipher

import org.bouncycastle.crypto.Wrapper; //导入依赖的package包/类
protected BaseWrapCipher(
    Wrapper wrapEngine,
    int ivSize)
{
    this.wrapEngine = wrapEngine;
    this.ivSize = ivSize;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:8,代码来源:BaseWrapCipher.java


示例12: generateEncryptedBytes

import org.bouncycastle.crypto.Wrapper; //导入依赖的package包/类
public byte[] generateEncryptedBytes(AlgorithmIdentifier keyEncryptionAlgorithm, byte[] derivedKey, GenericKey contentEncryptionKey)
    throws CMSException
{
    byte[] contentEncryptionKeySpec = ((KeyParameter)CMSUtils.getBcKey(contentEncryptionKey)).getKey();
    Wrapper keyEncryptionCipher = EnvelopedDataHelper.createRFC3211Wrapper(keyEncryptionAlgorithm.getAlgorithm());

    keyEncryptionCipher.init(true, new ParametersWithIV(new KeyParameter(derivedKey), ASN1OctetString.getInstance(keyEncryptionAlgorithm.getParameters()).getOctets()));

    return keyEncryptionCipher.wrap(contentEncryptionKeySpec, 0, contentEncryptionKeySpec.length);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:11,代码来源:BcPasswordRecipientInfoGenerator.java


示例13: wrapTest

import org.bouncycastle.crypto.Wrapper; //导入依赖的package包/类
private void wrapTest(
    int          id,
    BlockCipher  engine,
    byte[]       kek,
    byte[]       iv,
    SecureRandom rand,
    byte[]       in,
    byte[]       out)
    throws Exception
{
    Wrapper wrapper = new RFC3211WrapEngine(engine);

    wrapper.init(true, new ParametersWithRandom(new ParametersWithIV(new KeyParameter(kek), iv), rand));

    byte[]  cText = wrapper.wrap(in, 0, in.length);
    if (!Arrays.areEqual(cText, out))
    {
        fail("failed wrap test " + id  + " expected " + new String(Hex.encode(out)) + " got " + new String(Hex.encode(cText)));
    }

    wrapper.init(false, new ParametersWithIV(new KeyParameter(kek), iv));

    byte[]  pText = wrapper.unwrap(out, 0, out.length);
    if (!Arrays.areEqual(pText, in))
    {
        fail("rfailed unwrap test " + id  + " expected " + new String(Hex.encode(in)) + " got " + new String(Hex.encode(pText)));
    }
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:29,代码来源:RFC3211WrapTest.java


示例14: testCorruption

import org.bouncycastle.crypto.Wrapper; //导入依赖的package包/类
private void testCorruption()
    throws InvalidCipherTextException
{
    byte[] kek = Hex.decode("D1DAA78615F287E6");
    byte[] iv = Hex.decode("EFE598EF21B33D6D");

    Wrapper wrapper = new RFC3211WrapEngine(new DESEngine());

    wrapper.init(false, new ParametersWithIV(new KeyParameter(kek), iv));

    byte[] block = Hex.decode("ff739D838C627C897323A2F8C436F541");
    encryptBlock(kek, iv, block);

    try
    {
        wrapper.unwrap(block, 0, block.length);

        fail("bad length not detected");
    }
    catch (InvalidCipherTextException e)
    {
        if (!e.getMessage().equals("wrapped key corrupted"))
        {
            fail("wrong exception on length");
        }
    }

    block = Hex.decode("08639D838C627C897323A2F8C436F541");
    testChecksum(kek, iv, block, wrapper);

    block = Hex.decode("08736D838C627C897323A2F8C436F541");
    testChecksum(kek, iv, block, wrapper);
    
    block = Hex.decode("08739D638C627C897323A2F8C436F541");
    testChecksum(kek, iv, block, wrapper);
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:37,代码来源:RFC3211WrapTest.java


示例15: RFC6637

import org.bouncycastle.crypto.Wrapper; //导入依赖的package包/类
public RFC6637(
        Supplier<Wrapper> wrapperFactory,
        String curveName,
        int symAlgIDKeyLength,
        RFC6637KDF kdf
) throws IOException {

    this.wrapperFactory = Objects.requireNonNull(wrapperFactory, "wrapperFactory");
    this.curveName = Objects.requireNonNull(curveName, "curveName");
    this.symAlgIDKeyLength = symAlgIDKeyLength;
    this.kdf = Objects.requireNonNull(kdf, "kdf");
}
 
开发者ID:horrorho,项目名称:InflatableDonkey,代码行数:13,代码来源:RFC6637.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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