Exemplo n.º 1
0
        /// <summary>
        /// 采用RAS和DES一起进行加密操作,公钥加密Key/IV,Key和IV来加密源数据,可以指定具体采用的Key / Iv
        /// </summary>
        /// <param name="xmlPublicKey"></param>
        /// <param name="srcDataToEncrypted"></param>
        /// <returns></returns>
        public static RSADESEncryptResult EncryptByRSADES(string xmlPublicKey, string srcDataToEncrypted, DesKeyIVEntity keyIv)
        {
            RSADESEncryptResult result = new RSADESEncryptResult();

            //公钥加密Key
            result.EncryptedDesKeyIV = EncryptUtility.EncryptByRSA(string.Format("{0}.{1}", keyIv.KeyString, keyIv.IVString), Encoding.Unicode, xmlPublicKey);

            //Key和IV来加密源数据
            result.EncryptedSourceData = EncryptUtility.EncryptByDES(srcDataToEncrypted, Encoding.Unicode, keyIv.KeyBytes, keyIv.IVBytes);

            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 采用RAS和DES一起进行解密操作,私钥解析出来Key/IV,然后用Key/Iv解密业务数据
        /// </summary>
        /// <param name="xmlPrivateKey"></param>
        /// <param name="encryptResult"></param>
        /// <returns></returns>
        public static RSADESDecryptResult DecryptByRSADES(string xmlPrivateKey, RSADESEncryptResult encryptResult)
        {
            string[] encryptedKeyIv = EncryptUtility.DecryptByRSA(encryptResult.EncryptedDesKeyIV, Encoding.Unicode, xmlPrivateKey).Split('.');
            var      result         = new RSADESDecryptResult();

            result.DecryptedDesKey = encryptedKeyIv[0];
            result.DecryptedDesIv  = encryptedKeyIv[1];
            var keyIv = new DesKeyIVEntity()
            {
                KeyString = result.DecryptedDesKey, IVString = result.DecryptedDesIv
            };

            result.DecryptedSourceData = EncryptUtility.DecryptByDES(encryptResult.EncryptedSourceData, Encoding.Unicode, keyIv.KeyBytes, keyIv.IVBytes);
            return(result);
        }