Search in sources :

Example 1 with RecipientOperator

use of com.github.zhenwei.pkix.cms.RecipientOperator in project LinLong-Java by zhenwei1108.

the class BcRSAKeyTransEnvelopedRecipient method getRecipientOperator.

public RecipientOperator getRecipientOperator(AlgorithmIdentifier keyEncryptionAlgorithm, final AlgorithmIdentifier contentEncryptionAlgorithm, byte[] encryptedContentEncryptionKey) throws CMSException {
    CipherParameters secretKey = extractSecretKey(keyEncryptionAlgorithm, contentEncryptionAlgorithm, encryptedContentEncryptionKey);
    final Object dataCipher = EnvelopedDataHelper.createContentCipher(false, secretKey, contentEncryptionAlgorithm);
    return new RecipientOperator(new InputDecryptor() {

        public AlgorithmIdentifier getAlgorithmIdentifier() {
            return contentEncryptionAlgorithm;
        }

        public InputStream getInputStream(InputStream dataIn) {
            if (dataCipher instanceof BufferedBlockCipher) {
                return new CipherInputStream(dataIn, (BufferedBlockCipher) dataCipher);
            } else {
                return new CipherInputStream(dataIn, (StreamCipher) dataCipher);
            }
        }
    });
}
Also used : CipherParameters(com.github.zhenwei.core.crypto.CipherParameters) CipherInputStream(com.github.zhenwei.core.crypto.io.CipherInputStream) InputDecryptor(com.github.zhenwei.pkix.operator.InputDecryptor) CipherInputStream(com.github.zhenwei.core.crypto.io.CipherInputStream) InputStream(java.io.InputStream) BufferedBlockCipher(com.github.zhenwei.core.crypto.BufferedBlockCipher) RecipientOperator(com.github.zhenwei.pkix.cms.RecipientOperator) StreamCipher(com.github.zhenwei.core.crypto.StreamCipher) AlgorithmIdentifier(com.github.zhenwei.core.asn1.x509.AlgorithmIdentifier)

Example 2 with RecipientOperator

use of com.github.zhenwei.pkix.cms.RecipientOperator in project LinLong-Java by zhenwei1108.

the class JceKEKAuthenticatedRecipient method getRecipientOperator.

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();
        }
    });
}
Also used : JceGenericKey(com.github.zhenwei.pkix.operator.jcajce.JceGenericKey) OutputStream(java.io.OutputStream) MacOutputStream(com.github.zhenwei.provider.jcajce.io.MacOutputStream) RecipientOperator(com.github.zhenwei.pkix.cms.RecipientOperator) MacOutputStream(com.github.zhenwei.provider.jcajce.io.MacOutputStream) GenericKey(com.github.zhenwei.pkix.operator.GenericKey) JceGenericKey(com.github.zhenwei.pkix.operator.jcajce.JceGenericKey) Key(java.security.Key) SecretKey(javax.crypto.SecretKey) GenericKey(com.github.zhenwei.pkix.operator.GenericKey) JceGenericKey(com.github.zhenwei.pkix.operator.jcajce.JceGenericKey) Mac(javax.crypto.Mac) MacCalculator(com.github.zhenwei.pkix.operator.MacCalculator) AlgorithmIdentifier(com.github.zhenwei.core.asn1.x509.AlgorithmIdentifier)

Example 3 with RecipientOperator

use of com.github.zhenwei.pkix.cms.RecipientOperator in project LinLong-Java by zhenwei1108.

the class JceKEKEnvelopedRecipient method getRecipientOperator.

public RecipientOperator getRecipientOperator(AlgorithmIdentifier keyEncryptionAlgorithm, final AlgorithmIdentifier contentEncryptionAlgorithm, byte[] encryptedContentEncryptionKey) throws CMSException {
    Key secretKey = extractSecretKey(keyEncryptionAlgorithm, contentEncryptionAlgorithm, encryptedContentEncryptionKey);
    final Cipher dataCipher = contentHelper.createContentCipher(secretKey, contentEncryptionAlgorithm);
    return new RecipientOperator(new InputDecryptor() {

        public AlgorithmIdentifier getAlgorithmIdentifier() {
            return contentEncryptionAlgorithm;
        }

        public InputStream getInputStream(InputStream dataOut) {
            return new CipherInputStream(dataOut, dataCipher);
        }
    });
}
Also used : CipherInputStream(com.github.zhenwei.provider.jcajce.io.CipherInputStream) InputDecryptor(com.github.zhenwei.pkix.operator.InputDecryptor) CipherInputStream(com.github.zhenwei.provider.jcajce.io.CipherInputStream) InputStream(java.io.InputStream) RecipientOperator(com.github.zhenwei.pkix.cms.RecipientOperator) Cipher(javax.crypto.Cipher) Key(java.security.Key) SecretKey(javax.crypto.SecretKey) AlgorithmIdentifier(com.github.zhenwei.core.asn1.x509.AlgorithmIdentifier)

Example 4 with RecipientOperator

use of com.github.zhenwei.pkix.cms.RecipientOperator in project LinLong-Java by zhenwei1108.

the class JcePasswordEnvelopedRecipient method getRecipientOperator.

public RecipientOperator getRecipientOperator(AlgorithmIdentifier keyEncryptionAlgorithm, final AlgorithmIdentifier contentEncryptionAlgorithm, byte[] derivedKey, byte[] encryptedContentEncryptionKey) throws CMSException {
    Key secretKey = extractSecretKey(keyEncryptionAlgorithm, contentEncryptionAlgorithm, derivedKey, encryptedContentEncryptionKey);
    final Cipher dataCipher = helper.createContentCipher(secretKey, contentEncryptionAlgorithm);
    return new RecipientOperator(new InputDecryptor() {

        public AlgorithmIdentifier getAlgorithmIdentifier() {
            return contentEncryptionAlgorithm;
        }

        public InputStream getInputStream(InputStream dataOut) {
            return new CipherInputStream(dataOut, dataCipher);
        }
    });
}
Also used : CipherInputStream(com.github.zhenwei.provider.jcajce.io.CipherInputStream) InputDecryptor(com.github.zhenwei.pkix.operator.InputDecryptor) CipherInputStream(com.github.zhenwei.provider.jcajce.io.CipherInputStream) InputStream(java.io.InputStream) RecipientOperator(com.github.zhenwei.pkix.cms.RecipientOperator) Cipher(javax.crypto.Cipher) Key(java.security.Key) AlgorithmIdentifier(com.github.zhenwei.core.asn1.x509.AlgorithmIdentifier)

Example 5 with RecipientOperator

use of com.github.zhenwei.pkix.cms.RecipientOperator in project LinLong-Java by zhenwei1108.

the class JceKeyTransAuthEnvelopedRecipient method getRecipientOperator.

public RecipientOperator getRecipientOperator(AlgorithmIdentifier keyEncryptionAlgorithm, final AlgorithmIdentifier contentEncryptionAlgorithm, byte[] encryptedContentEncryptionKey) throws CMSException {
    Key secretKey = extractSecretKey(keyEncryptionAlgorithm, contentEncryptionAlgorithm, encryptedContentEncryptionKey);
    final Cipher dataCipher = contentHelper.createContentCipher(secretKey, contentEncryptionAlgorithm);
    return new RecipientOperator(new InputAEADDecryptor() {

        public AlgorithmIdentifier getAlgorithmIdentifier() {
            return contentEncryptionAlgorithm;
        }

        public InputStream getInputStream(InputStream dataIn) {
            return new CipherInputStream(dataIn, dataCipher);
        }

        public OutputStream getAADStream() {
            return new AADStream(dataCipher);
        }

        public byte[] getMAC() {
            // TODO
            return new byte[0];
        }
    });
}
Also used : InputAEADDecryptor(com.github.zhenwei.pkix.operator.InputAEADDecryptor) CipherInputStream(com.github.zhenwei.provider.jcajce.io.CipherInputStream) CipherInputStream(com.github.zhenwei.provider.jcajce.io.CipherInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) RecipientOperator(com.github.zhenwei.pkix.cms.RecipientOperator) Cipher(javax.crypto.Cipher) Key(java.security.Key) PrivateKey(java.security.PrivateKey) AlgorithmIdentifier(com.github.zhenwei.core.asn1.x509.AlgorithmIdentifier)

Aggregations

AlgorithmIdentifier (com.github.zhenwei.core.asn1.x509.AlgorithmIdentifier)14 RecipientOperator (com.github.zhenwei.pkix.cms.RecipientOperator)14 Key (java.security.Key)11 InputStream (java.io.InputStream)9 InputDecryptor (com.github.zhenwei.pkix.operator.InputDecryptor)8 PrivateKey (java.security.PrivateKey)7 CipherInputStream (com.github.zhenwei.provider.jcajce.io.CipherInputStream)6 OutputStream (java.io.OutputStream)6 Cipher (javax.crypto.Cipher)6 GenericKey (com.github.zhenwei.pkix.operator.GenericKey)5 MacCalculator (com.github.zhenwei.pkix.operator.MacCalculator)5 JceGenericKey (com.github.zhenwei.pkix.operator.jcajce.JceGenericKey)5 MacOutputStream (com.github.zhenwei.provider.jcajce.io.MacOutputStream)5 Mac (javax.crypto.Mac)5 BufferedBlockCipher (com.github.zhenwei.core.crypto.BufferedBlockCipher)3 StreamCipher (com.github.zhenwei.core.crypto.StreamCipher)3 CipherInputStream (com.github.zhenwei.core.crypto.io.CipherInputStream)2 KeyParameter (com.github.zhenwei.core.crypto.params.KeyParameter)2 SecretKey (javax.crypto.SecretKey)2 CipherParameters (com.github.zhenwei.core.crypto.CipherParameters)1