//Encrypt the input file and the symmetric key, save them as a file and return the DigitalEnvelopeEncrypted object //containing the encrypted message and the encrypted symmetric key. public DigitalEnvelopeEncrypted CreateEnvelope() { DigitalEnvelopeEncrypted = new DigitalEnvelopeEncrypted ( //Encrypt the input file. symmetricAlgorithm.Encrypt(input), //Encrypt the symmetric key. rsaAlgorithm.RSAEncrypt(symmetricAlgorithm.algorithm.Key, true) ); SaveEnvelope(); return(DigitalEnvelopeEncrypted); }
//Load envelope file. private void LoadEnvelope(string path) { FileIO fileInput = new FileIO(new StreamReader(path ?? InitialParameters.basePath + InitialParameters.envelopeFilePath)); fileInput.LoadFile(); string[] methods = fileInput.Method.Split('-'); symmetricAlgorithmName = methods[0]; rsaName = methods[1]; cipherName = fileInput.Cipher; initializationVector = Convert.FromBase64String(fileInput.InitializationVector); DigitalEnvelopeEncrypted = new DigitalEnvelopeEncrypted ( Convert.FromBase64String(fileInput.EnvelopeData), Convert.FromBase64String(fileInput.EnvelopeCryptKey) ); }