public static string PublicDecrypt(Envelope envelope, string publicKey) { RSAManager rsa = new RSAManager(publicKey); byte[] key = rsa.PublicDecrypt(Convert.FromBase64String(envelope.Key)); byte[] iv = rsa.PublicDecrypt(Convert.FromBase64String(envelope.IV)); RijndaelManager aes = new RijndaelManager(key, iv); return(aes.Decrypt(envelope.Data)); }
public static Envelope PrivateEncrypt(string id, string source, string privateKey) { Envelope envelope = new Envelope { Id = id }; byte[] key, iv; RijndaelManager.GenerateKeyAndIV(out key, out iv); RijndaelManager aes = new RijndaelManager(key, iv); envelope.Data = aes.Encrypt(source); RSAManager rsa = new RSAManager(privateKey); envelope.Key = Convert.ToBase64String(rsa.PrivateEncrypt(key)); envelope.IV = Convert.ToBase64String(rsa.PrivateEncrypt(iv)); return(envelope); }