Example #1
0
        public void CreateDigitalEnvelope(string text, string name)
        {
            byte[] encryptedMessage = AesClass.EncryptString(text);
            byte[] encryptedKey     = Rsa.Encrypt(Convert.ToBase64String(AesClass.Key));

            FileManager.WriteToXmlFile(name, Convert.ToBase64String(encryptedMessage));
            FileManager.WriteToXmlFile("IV", Convert.ToBase64String(AesClass.IV));
            FileManager.WriteToXmlFile("Key", Convert.ToBase64String(encryptedKey));
        }
Example #2
0
        public string OpenDigitalEnvelope(string name)
        {
            var message = FileManager.ReadFromXMLFile(name);
            var key     = FileManager.ReadFromXMLFile("Key");
            var iv      = FileManager.ReadFromXMLFile("IV");

            byte[] encryptedMessage = Convert.FromBase64String(message);
            byte[] encryptedKey     = Convert.FromBase64String(key);
            byte[] encryptedIv      = Convert.FromBase64String(iv);

            byte[] aesKey    = Convert.FromBase64String(Rsa.Decrypt(encryptedKey));
            string plainText = AesClass.DecryptString(encryptedMessage, aesKey, encryptedIv);

            return(plainText);
        }
Example #3
0
        /// <summary>
        /// 接口调用认证
        /// </summary>
        /// <param name="SECURITYKEY">认证码</param>
        /// <returns></returns>
        public bool API_Authentication(string SECURITYKEY)
        {
            var security = AesClass.AesDecrypt(SECURITYKEY, SyntacticSugar.ConfigSugar.GetAppString("API_EncryptionKey"));

            return(security == SyntacticSugar.ConfigSugar.GetAppString("API_AuthenticationValue"));
        }