Example #1
0
        public static EncryptedMessage Create(object value, string base64PubKey)
        {
            //base64Token is a public key in base64 string format

            try
            {
                EncryptedMessage result = new EncryptedMessage();

                RijndaelManaged rm = new RijndaelManaged();

                var encryptedMessage = RijndaelHelper.AesEncrypt(Newtonsoft.Json.JsonConvert.SerializeObject(value), rm.Key, rm.IV);

                result.Token = CryptoRSAHelper.RsaEncrypt(Convert.ToBase64String(rm.Key), base64PubKey);

                result.IV = Convert.ToBase64String(rm.IV);

                result.Message = encryptedMessage;

                return(result);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Example #2
0
        public static RsaMessage Create(object value, string base64PubKey)
        {
            try
            {
                RsaMessage result = new RsaMessage();

                var message = JsonConvert.SerializeObject(value);

                result.Message = CryptoRSAHelper.RsaEncrypt(message, base64PubKey);

                return(result);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }