//Mã hóa bất đối xứng secretkey = public key public void EncryptSecretKeywithASAlgorithm(String inputPublicFile) { //Tạo RSA ra, set chiều dài, đọc file Input Public, gán vào và mã hóa, trả về StreamReader srReader = new StreamReader(inputPublicFile); int KeyLength = int.Parse(srReader.ReadLine()); string ReadKey = srReader.ReadLine(); srReader.Close(); MyRSAAlgorithm myRSA = new MyRSAAlgorithm(); myRSA.SetKeyLength(KeyLength); m_EncryptedSecretKey = myRSA.EncryptData(m_SecretKey, ReadKey); }
//Mã hóa đối xứng Secretkey = Public Key truyền vào trực tiếp ko đọc File public void EncryptSecretKeyWithRSAAlgo_DirectPublicKey(string publicKey, int KeySize) { MyRSAAlgorithm myRSA = new MyRSAAlgorithm(); myRSA.SetKeyLength(KeySize); m_EncryptedSecretKey = myRSA.EncryptData(m_SecretKey, publicKey); }
//Giả mã Secret key dùng thuật toán RSA public void DecryptSecretKeywithRSAAlgorithm(string PrivateKey, int KeySize) { MyRSAAlgorithm myRSA = new MyRSAAlgorithm(); myRSA.SetKeyLength(KeySize); string DecryptedSecretKey = myRSA.DecryptData(m_EncryptedSecretKey, PrivateKey); m_SecretKey = DecryptedSecretKey;//gán Key đã mã hoá vào m_SecretKey }