/// <exception cref="System.IO.IOException"/> /// <exception cref="Org.BouncyCastle.Security.GeneralSecurityException"/> internal static DERForRecipientParams CalculateDERForRecipientParams(byte[] @in) { String s = "1.2.840.113549.3.2"; DERForRecipientParams parameters = new DERForRecipientParams(); byte[] outp = new byte[100]; DerObjectIdentifier derob = new DerObjectIdentifier(s); byte[] abyte0 = IVGenerator.GetIV(16); // keyp IBufferedCipher cf = CipherUtilities.GetCipher(derob); KeyParameter kp = new KeyParameter(abyte0); byte[] iv = IVGenerator.GetIV(cf.GetBlockSize()); ParametersWithIV piv = new ParametersWithIV(kp, iv); cf.Init(true, piv); int len = cf.DoFinal(@in, outp, 0); byte[] abyte1 = new byte[len]; Array.Copy(outp, 0, abyte1, 0, len); Asn1EncodableVector ev = new Asn1EncodableVector(); ev.Add(new DerInteger(58)); ev.Add(new DerOctetString(iv)); DerSequence seq = new DerSequence(ev); parameters.abyte0 = abyte0; parameters.abyte1 = abyte1; parameters.algorithmIdentifier = new AlgorithmIdentifier(derob, seq); return(parameters); }
internal static DERForRecipientParams CalculateDERForRecipientParams(byte[] @in) { /* * According to ISO 32000-2 (7.6.5.3 Public-key encryption algorithms) RC-2 algorithm is outdated * and should be replaced with a safer one 256-bit AES-CBC: * The algorithms that shall be used to encrypt the enveloped data in the CMS object are: * - RC4 with key lengths up to 256-bits (deprecated); * - DES, Triple DES, RC2 with key lengths up to 128 bits (deprecated); * - 128-bit AES in Cipher Block Chaining (CBC) mode (deprecated); * - 192-bit AES in CBC mode (deprecated); * - 256-bit AES in CBC mode. */ String s = "1.2.840.113549.3.2"; DERForRecipientParams parameters = new DERForRecipientParams(); byte[] outp = new byte[100]; DerObjectIdentifier derob = new DerObjectIdentifier(s); // keyp byte[] abyte0 = IVGenerator.GetIV(16); IBufferedCipher cf = CipherUtilities.GetCipher(derob); KeyParameter kp = new KeyParameter(abyte0); byte[] iv = IVGenerator.GetIV(cf.GetBlockSize()); ParametersWithIV piv = new ParametersWithIV(kp, iv); cf.Init(true, piv); int len = cf.DoFinal(@in, outp, 0); byte[] abyte1 = new byte[len]; Array.Copy(outp, 0, abyte1, 0, len); Asn1EncodableVector ev = new Asn1EncodableVector(); ev.Add(new DerInteger(58)); ev.Add(new DerOctetString(iv)); DerSequence seq = new DerSequence(ev); parameters.abyte0 = abyte0; parameters.abyte1 = abyte1; parameters.algorithmIdentifier = new AlgorithmIdentifier(derob, seq); return(parameters); }