//---------------------------------------------------------------------------------------------------- public static string DecryptClient(AESKeyInfo aesKeyInfo, string cipherText) { var key = ASPdb.Security.AESLogic.CryptoJS_enc_Base64_parse(aesKeyInfo.Key); var iv = ASPdb.Security.AESLogic.CryptoJS_enc_Base64_parse(aesKeyInfo.IV); string decrypted = AESLogic.CryptoJS_AES_decrypt(cipherText, key, 128 / 8, iv); string plainText = ASPdb.Security.AESLogic.ToString_UTF8(decrypted); return(plainText); }
//---------------------------------------------------------------------------------------------------- public static string EncryptClient(AESKeyInfo aesKeyInfo, string message) { var key = ASPdb.Security.AESLogic.CryptoJS_enc_Base64_parse(aesKeyInfo.Key); var iv = ASPdb.Security.AESLogic.CryptoJS_enc_Base64_parse(aesKeyInfo.IV); var parsedText = AESLogic.CryptoJS_enc_Utf8_parse(message); var cipherText = AESLogic.CryptoJS_AES_encrypt(parsedText, key, 128 / 8, iv); return(cipherText); }
public static string DecryptServer(AESKeyInfo aesKeyInfo, string cipherText) { var key_Bytes = Convert.FromBase64String(aesKeyInfo.Key); var iv_Bytes = Convert.FromBase64String(aesKeyInfo.IV); byte[] cipherBytes = Convert.FromBase64String(cipherText); var plainText = DecryptStringFromBytes(cipherBytes, key_Bytes, iv_Bytes); return(plainText); }
public static string EncryptServer(AESKeyInfo aesKeyInfo, string message) { var key_Bytes = Convert.FromBase64String(aesKeyInfo.Key); var iv_Bytes = Convert.FromBase64String(aesKeyInfo.IV); byte[] cipherBytes = EncryptStringToBytes(message, key_Bytes, iv_Bytes); var encrypted = Convert.ToBase64String(cipherBytes); return(encrypted); }
//---------------------------------------------------------------------------------------------------- private void Create_and_Send_AESKey() { this.AESKey = AESLogic.CreateNewAES(); JsString json = this.AESKey.ToJson(); string base64 = ""; string pem = this.PublicKeyPem; eval(@" var jsEncrypt = new JSEncrypt(); jsEncrypt.setKey(pem); base64 = jsEncrypt.encrypt(json); "); ASPdatabaseNET.AjaxService.ASPdatabaseService .New(this, "SendAESKey_Return") .NoEncryption() .Authentication__SendAESKey(this.AESIndex, base64); }
//---------------------------------------------------------------------------------------------------- public static AESKeyInfo CreateNewAES() { var rtn = new AESKeyInfo(); rtn.A = RandomBase64(1, 23); rtn.B = RandomBase64(0, 11); rtn.C = RandomBase64(0, 11); rtn.D = RandomBase64(1, 23); rtn.Pass = RandomBase64(25, 30); var salt1 = AESLogic.CryptoJS_lib_WordArray_random(128 / 8); var key = AESLogic.CryptoJS_PBKDF2(rtn.Pass, salt1, 128 / 32, 200); rtn.Key = "" + AESLogic.CryptoJS_enc_Base64_stringify(key); var salt2 = AESLogic.CryptoJS_lib_WordArray_random(128 / 8); var iv = AESLogic.CryptoJS_PBKDF2(rtn.Pass, salt2, 128 / 32, 200); rtn.IV = "" + AESLogic.CryptoJS_enc_Base64_stringify(iv); return(rtn); }