Esempio n. 1
0
            public ICmsReadable GetReadable(KeyParameter sKey)
            {
                try
                {
                    this.cipher = CipherUtilities.GetCipher(this.algorithm.ObjectID);

                    Asn1Encodable asn1Enc    = this.algorithm.Parameters;
                    Asn1Object    asn1Params = asn1Enc == null ? null : asn1Enc.ToAsn1Object();

                    ICipherParameters cipherParameters = sKey;

                    if (asn1Params != null && !(asn1Params is Asn1Null))
                    {
                        cipherParameters = ParameterUtilities.GetCipherParameters(
                            this.algorithm.ObjectID, cipherParameters, asn1Params);
                    }
                    else
                    {
                        string alg = this.algorithm.ObjectID.Id;
                        if (alg.Equals(CmsEnvelopedDataGenerator.DesEde3Cbc) ||
                            alg.Equals(CmsEnvelopedDataGenerator.IdeaCbc) ||
                            alg.Equals(CmsEnvelopedDataGenerator.Cast5Cbc))
                        {
                            cipherParameters = new ParametersWithIV(cipherParameters, new byte[8]);
                        }
                    }

                    cipher.Init(false, cipherParameters);
                }
                catch (SecurityUtilityException e)
                {
                    throw new CmsException("couldn't create cipher.", e);
                }
                catch (InvalidKeyException e)
                {
                    throw new CmsException("key invalid in message.", e);
                }
                catch (IOException e)
                {
                    throw new CmsException("error decoding algorithm parameters.", e);
                }

                try
                {
                    return(new CmsProcessableInputStream(
                               new CipherStream(readable.GetInputStream(), cipher, null)));
                }
                catch (IOException e)
                {
                    throw new CmsException("error reading content.", e);
                }
            }
Esempio n. 2
0
        internal CmsTypedStream GetContentFromSessionKey(
            KeyParameter sKey)
        {
            ICmsReadable readable = secureReadable.GetReadable(sKey);

            try
            {
                return(new CmsTypedStream(readable.GetInputStream()));
            }
            catch (IOException e)
            {
                throw new CmsException("error getting .", e);
            }
        }
Esempio n. 3
0
            public ICmsReadable GetReadable(KeyParameter sKey)
            {
                string macAlg = this.algorithm.ObjectID.Id;

//				Asn1Object sParams = this.algorithm.Parameters.ToAsn1Object();

                try
                {
                    this.mac = MacUtilities.GetMac(macAlg);

                    // FIXME Support for MAC algorithm parameters similar to cipher parameters
//						ASN1Object sParams = (ASN1Object)macAlg.getParameters();
//
//						if (sParams != null && !(sParams instanceof ASN1Null))
//						{
//							AlgorithmParameters params = CMSEnvelopedHelper.INSTANCE.createAlgorithmParameters(macAlg.getObjectId().getId(), provider);
//
//							params.init(sParams.getEncoded(), "ASN.1");
//
//							mac.init(sKey, params.getParameterSpec(IvParameterSpec.class));
//						}
//						else
                    {
                        mac.Init(sKey);
                    }

//						Asn1Object asn1Params = asn1Enc == null ? null : asn1Enc.ToAsn1Object();
//
//						ICipherParameters cipherParameters = sKey;
//
//						if (asn1Params != null && !(asn1Params is Asn1Null))
//						{
//							cipherParameters = ParameterUtilities.GetCipherParameters(
//							macAlg.ObjectID, cipherParameters, asn1Params);
//						}
//						else
//						{
//							string alg = macAlg.ObjectID.Id;
//							if (alg.Equals(CmsEnvelopedDataGenerator.DesEde3Cbc)
//								|| alg.Equals(CmsEnvelopedDataGenerator.IdeaCbc)
//								|| alg.Equals(CmsEnvelopedDataGenerator.Cast5Cbc))
//							{
//								cipherParameters = new ParametersWithIV(cipherParameters, new byte[8]);
//							}
//						}
//
//						mac.Init(cipherParameters);
                }
                catch (SecurityUtilityException e)
                {
                    throw new CmsException("couldn't create cipher.", e);
                }
                catch (InvalidKeyException e)
                {
                    throw new CmsException("key invalid in message.", e);
                }
                catch (IOException e)
                {
                    throw new CmsException("error decoding algorithm parameters.", e);
                }

                try
                {
                    return(new CmsProcessableInputStream(
                               new TeeInputStream(
                                   readable.GetInputStream(),
                                   new MacOutputStream(this.mac))));
                }
                catch (IOException e)
                {
                    throw new CmsException("error reading content.", e);
                }
            }