• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

Java GenericKey类的典型用法和代码示例

java 2次浏览

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

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

示例1: generateEncryptedBytes

点赞 3

import org.bouncycastle.operator.GenericKey; //导入依赖的package包/类
public byte[] generateEncryptedBytes(AlgorithmIdentifier keyEncryptionAlgorithm, byte[] derivedKey, GenericKey contentEncryptionKey)
    throws CMSException
{
    Key contentEncryptionKeySpec = helper.getJceKey(contentEncryptionKey);
    Cipher keyEncryptionCipher = helper.createRFC3211Wrapper(keyEncryptionAlgorithm.getAlgorithm());

    try
    {
        IvParameterSpec ivSpec = new IvParameterSpec(ASN1OctetString.getInstance(keyEncryptionAlgorithm.getParameters()).getOctets());

        keyEncryptionCipher.init(Cipher.WRAP_MODE, new SecretKeySpec(derivedKey, keyEncryptionCipher.getAlgorithm()), ivSpec);

        return keyEncryptionCipher.wrap(contentEncryptionKeySpec);
    }
    catch (GeneralSecurityException e)
    {
        throw new CMSException("cannot process content encryption key: " + e.getMessage(), e);
    }
}
 

开发者ID:thedrummeraki,
项目名称:Aki-SSL,
代码行数:20,
代码来源:JcePasswordRecipientInfoGenerator.java

示例2: generateWrappedKey

点赞 3

import org.bouncycastle.operator.GenericKey; //导入依赖的package包/类
public byte[] generateWrappedKey(GenericKey encryptionKey)
    throws OperatorException
{
    byte[] contentEncryptionKeySpec = OperatorUtils.getKeyBytes(encryptionKey);

    if (random == null)
    {
        wrapper.init(true, wrappingKey);
    }
    else
    {
        wrapper.init(true, new ParametersWithRandom(wrappingKey, random));
    }

    return wrapper.wrap(contentEncryptionKeySpec, 0, contentEncryptionKeySpec.length);
}
 

开发者ID:Appdome,
项目名称:ipack,
代码行数:17,
代码来源:BcSymmetricKeyWrapper.java

示例3: generateUnwrappedKey

点赞 3

import org.bouncycastle.operator.GenericKey; //导入依赖的package包/类
public GenericKey generateUnwrappedKey(AlgorithmIdentifier encryptedKeyAlgorithm, byte[] encryptedKey)
    throws OperatorException
{
    AsymmetricBlockCipher keyCipher = createAsymmetricUnwrapper(this.getAlgorithmIdentifier().getAlgorithm());

    keyCipher.init(false, privateKey);
    try
    {
        byte[] key = keyCipher.processBlock(encryptedKey, 0, encryptedKey.length);

        if (encryptedKeyAlgorithm.getAlgorithm().equals(PKCSObjectIdentifiers.des_EDE3_CBC))
        {
            return new GenericKey(encryptedKeyAlgorithm, key);
        }
        else
        {
            return new GenericKey(encryptedKeyAlgorithm, key);
        }
    }
    catch (InvalidCipherTextException e)
    {
        throw new OperatorException("unable to recover secret key: " + e.getMessage(), e);
    }
}
 

开发者ID:Appdome,
项目名称:ipack,
代码行数:25,
代码来源:BcAsymmetricKeyUnwrapper.java

示例4: generateWrappedKey

点赞 3

import org.bouncycastle.operator.GenericKey; //导入依赖的package包/类
public byte[] generateWrappedKey(GenericKey encryptionKey)
    throws OperatorException
{
    Key contentEncryptionKeySpec = OperatorUtils.getJceKey(encryptionKey);

    Cipher keyEncryptionCipher = helper.createSymmetricWrapper(this.getAlgorithmIdentifier().getAlgorithm());

    try
    {
        keyEncryptionCipher.init(Cipher.WRAP_MODE, wrappingKey, random);

        return keyEncryptionCipher.wrap(contentEncryptionKeySpec);
    }
    catch (GeneralSecurityException e)
    {
        throw new OperatorException("cannot wrap key: " + e.getMessage(), e);
    }
}
 

开发者ID:Appdome,
项目名称:ipack,
代码行数:19,
代码来源:JceSymmetricKeyWrapper.java

示例5: doOpen

点赞 3

import org.bouncycastle.operator.GenericKey; //导入依赖的package包/类
private OutputStream doOpen(
    ASN1ObjectIdentifier dataType,
    OutputStream         out,
    OutputEncryptor      encryptor)
    throws IOException, CMSException
{
    ASN1EncodableVector recipientInfos = new ASN1EncodableVector();
    GenericKey encKey = encryptor.getKey();
    Iterator it = recipientInfoGenerators.iterator();

    while (it.hasNext())
    {
        RecipientInfoGenerator recipient = (RecipientInfoGenerator)it.next();

        recipientInfos.add(recipient.generate(encKey));
    }

    return open(dataType, out, recipientInfos, encryptor);
}
 

开发者ID:Appdome,
项目名称:ipack,
代码行数:20,
代码来源:CMSEnvelopedDataStreamGenerator.java

示例6: generateUnwrappedKey

点赞 3

import org.bouncycastle.operator.GenericKey; //导入依赖的package包/类
public GenericKey generateUnwrappedKey(AlgorithmIdentifier encryptedKeyAlgorithm, byte[] encryptedKey)
    throws OperatorException
{
    GenericHybridParameters params = GenericHybridParameters.getInstance(this.getAlgorithmIdentifier().getParameters());
    Cipher keyCipher = helper.createAsymmetricWrapper(this.getAlgorithmIdentifier().getAlgorithm(), extraMappings);
    String symmetricWrappingAlg = helper.getWrappingAlgorithmName(params.getDem().getAlgorithm());
    RsaKemParameters kemParameters = RsaKemParameters.getInstance(params.getKem().getParameters());
    int keySizeInBits = kemParameters.getKeyLength().intValue() * 8;
    Key sKey;

    try
    {
        DEROtherInfo otherInfo = new DEROtherInfo.Builder(params.getDem(), partyUInfo, partyVInfo).build();
        KTSParameterSpec ktsSpec = new KTSParameterSpec.Builder(symmetricWrappingAlg, keySizeInBits, otherInfo.getEncoded()).withKdfAlgorithm(kemParameters.getKeyDerivationFunction()).build();

        keyCipher.init(Cipher.UNWRAP_MODE, privKey, ktsSpec);

        sKey = keyCipher.unwrap(encryptedKey, helper.getKeyAlgorithmName(encryptedKeyAlgorithm.getAlgorithm()), Cipher.SECRET_KEY);
    }
    catch (Exception e)
    {
        throw new OperatorException("Unable to unwrap contents key: " + e.getMessage(), e);
    }

    return new JceGenericKey(encryptedKeyAlgorithm, sKey);
}
 

开发者ID:thedrummeraki,
项目名称:Aki-SSL,
代码行数:27,
代码来源:JceKTSKeyUnwrapper.java

示例7: generateWrappedKey

点赞 3

import org.bouncycastle.operator.GenericKey; //导入依赖的package包/类
public byte[] generateWrappedKey(GenericKey encryptionKey)
    throws OperatorException
{
    Cipher keyEncryptionCipher = helper.createAsymmetricWrapper(getAlgorithmIdentifier().getAlgorithm(), new HashMap());

    try
    {
        DEROtherInfo otherInfo = new DEROtherInfo.Builder(JceSymmetricKeyWrapper.determineKeyEncAlg(symmetricWrappingAlg, keySizeInBits), partyUInfo, partyVInfo).build();
        KTSParameterSpec ktsSpec = new KTSParameterSpec.Builder(symmetricWrappingAlg, keySizeInBits, otherInfo.getEncoded()).build();

        keyEncryptionCipher.init(Cipher.WRAP_MODE, publicKey, ktsSpec, random);

        return keyEncryptionCipher.wrap(OperatorUtils.getJceKey(encryptionKey));
    }
    catch (Exception e)
    {
        throw new OperatorException("Unable to wrap contents key: " + e.getMessage(), e);
    }
}
 

开发者ID:thedrummeraki,
项目名称:Aki-SSL,
代码行数:20,
代码来源:JceKTSKeyWrapper.java

示例8: generateWrappedKey

点赞 3

import org.bouncycastle.operator.GenericKey; //导入依赖的package包/类
public byte[] generateWrappedKey(GenericKey encryptionKey)
    throws OperatorException
{
    AsymmetricBlockCipher keyEncryptionCipher = createAsymmetricWrapper(getAlgorithmIdentifier().getAlgorithm());
    
    CipherParameters params = publicKey;
    if (random != null)
    {
        params = new ParametersWithRandom(params, random);
    }

    try
    {
        byte[] keyEnc = OperatorUtils.getKeyBytes(encryptionKey);
        keyEncryptionCipher.init(true, publicKey);
        return keyEncryptionCipher.processBlock(keyEnc, 0, keyEnc.length);
    }
    catch (InvalidCipherTextException e)
    {
        throw new OperatorException("unable to encrypt contents key", e);
    }
}
 

开发者ID:credentials,
项目名称:irma_future_id,
代码行数:23,
代码来源:BcAsymmetricKeyWrapper.java

示例9: generateUnwrappedKey

点赞 2

import org.bouncycastle.operator.GenericKey; //导入依赖的package包/类
public GenericKey generateUnwrappedKey(AlgorithmIdentifier encryptedKeyAlgorithm, byte[] encryptedKey)
    throws OperatorException
{
    wrapper.init(false, wrappingKey);

    try
    {
        return new GenericKey(encryptedKeyAlgorithm, wrapper.unwrap(encryptedKey, 0, encryptedKey.length));
    }
    catch (InvalidCipherTextException e)
    {
        throw new OperatorException("unable to unwrap key: " + e.getMessage(), e);
    }
}
 

开发者ID:Appdome,
项目名称:ipack,
代码行数:15,
代码来源:BcSymmetricKeyUnwrapper.java

示例10: getKeyBytes

点赞 2

import org.bouncycastle.operator.GenericKey; //导入依赖的package包/类
static byte[] getKeyBytes(GenericKey key)
{
    if (key.getRepresentation() instanceof Key)
    {
        return ((Key)key.getRepresentation()).getEncoded();
    }

    if (key.getRepresentation() instanceof byte[])
    {
        return (byte[])key.getRepresentation();
    }

    throw new IllegalArgumentException("unknown generic key type");
}
 

开发者ID:Appdome,
项目名称:ipack,
代码行数:15,
代码来源:OperatorUtils.java

示例11: getJceKey

点赞 2

import org.bouncycastle.operator.GenericKey; //导入依赖的package包/类
static Key getJceKey(GenericKey key)
{
    if (key.getRepresentation() instanceof Key)
    {
        return (Key)key.getRepresentation();
    }

    if (key.getRepresentation() instanceof byte[])
    {
        return new SecretKeySpec((byte[])key.getRepresentation(), "ENC");
    }

    throw new IllegalArgumentException("unknown generic key type");
}
 

开发者ID:Appdome,
项目名称:ipack,
代码行数:15,
代码来源:OperatorUtils.java

示例12: build

点赞 2

import org.bouncycastle.operator.GenericKey; //导入依赖的package包/类
public InputDecryptorProvider build(final char[] password)
{
    return new InputDecryptorProvider()
    {
        public InputDecryptor get(final AlgorithmIdentifier algorithmIdentifier)
        {
            final PaddedBufferedBlockCipher engine = PKCS12PBEUtils.getEngine(algorithmIdentifier.getAlgorithm());

            PKCS12PBEParams           pbeParams = PKCS12PBEParams.getInstance(algorithmIdentifier.getParameters());

            CipherParameters params = PKCS12PBEUtils.createCipherParameters(algorithmIdentifier.getAlgorithm(), digest, engine.getBlockSize(), pbeParams, password);

            engine.init(false, params);

            return new InputDecryptor()
            {
                public AlgorithmIdentifier getAlgorithmIdentifier()
                {
                    return algorithmIdentifier;
                }

                public InputStream getInputStream(InputStream input)
                {
                    return new CipherInputStream(input, engine);
                }

                public GenericKey getKey()
                {
                    return new GenericKey(PKCS12ParametersGenerator.PKCS12PasswordToBytes(password));
                }
            };
        }
    };

}
 

开发者ID:Appdome,
项目名称:ipack,
代码行数:36,
代码来源:BcPKCS12PBEInputDecryptorProviderBuilder.java

示例13: createMacCalculator

点赞 2

import org.bouncycastle.operator.GenericKey; //导入依赖的package包/类
static MacCalculator createMacCalculator(final ASN1ObjectIdentifier digestAlgorithm, ExtendedDigest digest, final PKCS12PBEParams pbeParams, final char[] password)
{
    PKCS12ParametersGenerator pGen = new PKCS12ParametersGenerator(digest);

    pGen.init(PKCS12ParametersGenerator.PKCS12PasswordToBytes(password), pbeParams.getIV(), pbeParams.getIterations().intValue());

    final KeyParameter keyParam = (KeyParameter)pGen.generateDerivedMacParameters(digest.getDigestSize() * 8);

    final HMac hMac = new HMac(digest);

    hMac.init(keyParam);

    return new MacCalculator()
    {
        public AlgorithmIdentifier getAlgorithmIdentifier()
        {
            return new AlgorithmIdentifier(digestAlgorithm, pbeParams);
        }

        public OutputStream getOutputStream()
        {
            return new MacOutputStream(hMac);
        }

        public byte[] getMac()
        {
            byte[] res = new byte[hMac.getMacSize()];

            hMac.doFinal(res, 0);

            return res;
        }

        public GenericKey getKey()
        {
            return new GenericKey(getAlgorithmIdentifier(), PKCS12ParametersGenerator.PKCS12PasswordToBytes(password));
        }
    };
}
 

开发者ID:Appdome,
项目名称:ipack,
代码行数:40,
代码来源:PKCS12PBEUtils.java

示例14: generate

点赞 2

import org.bouncycastle.operator.GenericKey; //导入依赖的package包/类
public final RecipientInfo generate(GenericKey contentEncryptionKey)
    throws CMSException
{
    try
    {
        ASN1OctetString encryptedKey = new DEROctetString(wrapper.generateWrappedKey(contentEncryptionKey));

        return new RecipientInfo(new KEKRecipientInfo(kekIdentifier, wrapper.getAlgorithmIdentifier(), encryptedKey));
    }
    catch (OperatorException e)
    {
        throw new CMSException("exception wrapping content key: " + e.getMessage(), e);
    }
}
 

开发者ID:Appdome,
项目名称:ipack,
代码行数:15,
代码来源:KEKRecipientInfoGenerator.java

示例15: getBcKey

点赞 2

import org.bouncycastle.operator.GenericKey; //导入依赖的package包/类
static CipherParameters getBcKey(GenericKey key)
{
    if (key.getRepresentation() instanceof CipherParameters)
    {
        return (CipherParameters)key.getRepresentation();
    }

    if (key.getRepresentation() instanceof byte[])
    {
        return new KeyParameter((byte[])key.getRepresentation());
    }

    throw new IllegalArgumentException("unknown generic key type");
}
 

开发者ID:Appdome,
项目名称:ipack,
代码行数:15,
代码来源:CMSUtils.java

示例16: generateEncryptedBytes

点赞 2

import org.bouncycastle.operator.GenericKey; //导入依赖的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

示例17: getRecipientOperator

点赞 2

import org.bouncycastle.operator.GenericKey; //导入依赖的package包/类
public RecipientOperator getRecipientOperator(AlgorithmIdentifier keyEncryptionAlgorithm, final AlgorithmIdentifier contentMacAlgorithm, byte[] encryptedContentEncryptionKey)
    throws CMSException
{
    final Key secretKey = extractSecretKey(keyEncryptionAlgorithm, contentMacAlgorithm, encryptedContentEncryptionKey);

    final Mac dataMac = contentHelper.createContentMac(secretKey, contentMacAlgorithm);

    return new RecipientOperator(new MacCalculator()
    {
        public AlgorithmIdentifier getAlgorithmIdentifier()
        {
            return contentMacAlgorithm;
        }

        public GenericKey getKey()
        {
            return new JceGenericKey(contentMacAlgorithm, secretKey);
        }

        public OutputStream getOutputStream()
        {
            return new MacOutputStream(dataMac);
        }

        public byte[] getMac()
        {
            return dataMac.doFinal();
        }
    });
}
 

开发者ID:Appdome,
项目名称:ipack,
代码行数:31,
代码来源:JceKEKAuthenticatedRecipient.java

示例18: getRecipientOperator

点赞 2

import org.bouncycastle.operator.GenericKey; //导入依赖的package包/类
public RecipientOperator getRecipientOperator(AlgorithmIdentifier keyEncryptionAlgorithm, final AlgorithmIdentifier contentMacAlgorithm, byte[] encryptedContentEncryptionKey)
    throws CMSException
{
    final Key secretKey = extractSecretKey(keyEncryptionAlgorithm, contentMacAlgorithm, encryptedContentEncryptionKey);

    final Mac dataMac = contentHelper.createContentMac(secretKey, contentMacAlgorithm);

    return new RecipientOperator(new MacCalculator()
    {
        public AlgorithmIdentifier getAlgorithmIdentifier()
        {
            return contentMacAlgorithm;
        }

        public GenericKey getKey()
        {
            return new GenericKey(secretKey);
        }

        public OutputStream getOutputStream()
        {
            return new MacOutputStream(dataMac);
        }

        public byte[] getMac()
        {
            return dataMac.doFinal();
        }
    });
}
 

开发者ID:Appdome,
项目名称:ipack,
代码行数:31,
代码来源:JceKeyTransAuthenticatedRecipient.java

示例19: getJceKey

点赞 2

import org.bouncycastle.operator.GenericKey; //导入依赖的package包/类
Key getJceKey(GenericKey key)
{
    if (key.getRepresentation() instanceof Key)
    {
        return (Key)key.getRepresentation();
    }

    if (key.getRepresentation() instanceof byte[])
    {
        return new SecretKeySpec((byte[])key.getRepresentation(), "ENC");
    }

    throw new IllegalArgumentException("unknown generic key type");
}
 

开发者ID:Appdome,
项目名称:ipack,
代码行数:15,
代码来源:EnvelopedDataHelper.java


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)