Hi. This is my code.
public SLQ() { InitializeComponent(); rsa = new RSACryptoServiceProvider(); rsa.KeySize = 2048; } RSACryptoServiceProvider rsa; string fileName; public void SaveFile(RSACryptoServiceProvider rsa) { string path = Application.StartupPath; fileName = Path.Combine(path, "PCInfo.txt"); using (StreamWriter sw = new StreamWriter(fileName)) { string OSInfo = "OS Info: " + WritePCInfo.OSInfo; string BiosSerial = "BIOS Serial: " + WritePCInfo.BiosSerial; string HDDSerial = "HDD Serial: " + WritePCInfo.HDDSerial; string MotherboardSerial = "Motherboard Serial: " + WritePCInfo.MotherboardSerial; string MacAdress = "MAC Address: " + WritePCInfo.MacAdress; // Concatenate the strings string DATAS = ""; string[] infoArray = { OSInfo, BiosSerial, HDDSerial, MotherboardSerial, MacAdress }; for (int i = 0; i < infoArray.Length; i++) { DATAS += infoArray[i]; byte[] data = Encoding.UTF8.GetBytes(DATAS); byte[] encryptedData = rsa.Encrypt(data, RSAEncryptionPadding.OaepSHA256); string base64EncryptedData = Convert.ToBase64String(encryptedData); sw.WriteLine(base64EncryptedData); } } }
It works correctly when I replace "RSAEncryptionPadding.OaepSHA256" with "RSAEncryptionPadding.Pkcs1". I want to encrypt with OaepSHA256 or OaepSHA512. How can I do it?
I am using .Net framework 4.8