Exemple #1
0
        /// <summary>
        /// 加密
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public Task <JsonResult> EncryptData([FromBody] SecretKey model)
        {
            RSAHelper rsaHelper = new RSAHelper();

            //入参的字符串采用该方式转换成 字节数组
            byte[] byteArray = System.Text.Encoding.Default.GetBytes(model.StringData);
            //设置公钥配置
            RSAParameters publicParameters = RSAHelper.ToRSAParameters(model.PublicKey);
            //加密
            var encryptDataByte = rsaHelper.EncryptData(byteArray, publicParameters, model.RsaEncryptionPadding);
            //转换 64进制编码字段,解码需采用同类方式解码
            string encryptData = RSAHelper.ToByteString(encryptDataByte);

            return(Task.FromResult(Json(encryptData)));
        }