Я попытался реализовать функцию шифрования RSA на C# с использованием .NET v8. Тест шифрования прошел гладко, но во время теста дешифрования произошло непредвиденное исключение.
ДЕТАЛЬ ОШИБКИ:
System.Security.Cryptography.CryptographicException
HResult=0xC100000D
Message=Unknown error (0xc100000d)
Source=System.Security.Cryptography
StackTrace:
at Interop.BCrypt.BCryptEncryptRsa(SafeBCryptKeyHandle key, ReadOnlySpan`1 source, Span`1 destination, Void* pPaddingInfo, BCryptEncryptFlags dwFlags)
at System.Security.Cryptography.RSABCrypt.TryEncrypt(ReadOnlySpan`1 data, Span`1 destination, RSAEncryptionPadding padding, Int32& bytesWritten)
at System.Security.Cryptography.RSA.Encrypt(ReadOnlySpan`1 data, Span`1 destination, RSAEncryptionPadding padding)
at System.Security.Cryptography.RSABCrypt.Encrypt(Byte[] data, RSAEncryptionPadding padding)
at FileCryptography.FileEncryptionUtility.Encrypt(Byte[] data, String pemKey) in Class1.cs:line 51
at FileCryptography.FileEncryptionUtility.EncryptFile(String filePath, String pemKey) in Class1.cs:line 25
at FileCryptography.FileEncryptionUtility.File_encryption(Boolean Is_encrypt, String File_path, String PEMkey) in Class1.cs:line 14
at Cry.Form.File_crypt(Boolean Is_encrypt, String File_path) in Form1.cs:line 114
at Cry.Form.Form_Load(Object sender, EventArgs e) in Form1.cs:line 203
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Control.CreateControl(Boolean ignoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(HWND hWnd, MessageId msg, WPARAM wparam, LPARAM lparam)
Я попытался реализовать функцию шифрования RSA на C# с использованием .NET v8. Тест шифрования прошел гладко, но во время теста дешифрования произошло непредвиденное исключение. ДЕТАЛЬ ОШИБКИ: [code]System.Security.Cryptography.CryptographicException HResult=0xC100000D Message=Unknown error (0xc100000d) Source=System.Security.Cryptography StackTrace: at Interop.BCrypt.BCryptEncryptRsa(SafeBCryptKeyHandle key, ReadOnlySpan`1 source, Span`1 destination, Void* pPaddingInfo, BCryptEncryptFlags dwFlags) at System.Security.Cryptography.RSABCrypt.TryEncrypt(ReadOnlySpan`1 data, Span`1 destination, RSAEncryptionPadding padding, Int32& bytesWritten) at System.Security.Cryptography.RSA.Encrypt(ReadOnlySpan`1 data, Span`1 destination, RSAEncryptionPadding padding) at System.Security.Cryptography.RSABCrypt.Encrypt(Byte[] data, RSAEncryptionPadding padding) at FileCryptography.FileEncryptionUtility.Encrypt(Byte[] data, String pemKey) in Class1.cs:line 51 at FileCryptography.FileEncryptionUtility.EncryptFile(String filePath, String pemKey) in Class1.cs:line 25 at FileCryptography.FileEncryptionUtility.File_encryption(Boolean Is_encrypt, String File_path, String PEMkey) in Class1.cs:line 14 at Cry.Form.File_crypt(Boolean Is_encrypt, String File_path) in Form1.cs:line 114 at Cry.Form.Form_Load(Object sender, EventArgs e) in Form1.cs:line 203 at System.Windows.Forms.Form.OnLoad(EventArgs e) at System.Windows.Forms.Control.CreateControl(Boolean ignoreVisible) at System.Windows.Forms.Control.CreateControl() at System.Windows.Forms.Control.WmShowWindow(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(HWND hWnd, MessageId msg, WPARAM wparam, LPARAM lparam)
[/code] Вот мой код: [code]Class1.cs[/code] [code]using System; using System.IO; using System.Security.Cryptography; using System.Text;
namespace FileCryptography { public class FileEncryptionUtility { public static void File_encryption(bool Is_encrypt, string File_path, string PEMkey) { if (Is_encrypt) { EncryptFile(File_path, PEMkey); } else { DecryptFile(File_path, PEMkey); } }
Я использую .NET Framework 4.8 и получаю исключение, когда хочу расшифровать свой ключ.
Мой ключ: GRa22IQfZEhyQspHlYbH298LL9ByAy/cqkncc563ErI=
Мой пароль: JXg++525m7zDlr2HUrqkmwY29tOF8gK7hIUwT6mYzTk=
Я получаю исключение Get...
Я использую .NET Framework 4.8 и получаю исключение при расшифровке своего ключа.
Мой ключ: GRa22IQfZEhyQspHlYbH298LL9ByAy/cqkncc563ErI=
Мой пароль это: JXg++525m7zDlr2HUrqkmwY29tOF8gK7hIUwT6mYzTk=
Я получаю исключение Get...
Я использую .NET Framework 4.8 и получаю исключение при расшифровке своего ключа.
Мой ключ: GRa22IQfZEhyQspHlYbH298LL9ByAy/cqkncc563ErI=
Мой пароль это: JXg++525m7zDlr2HUrqkmwY29tOF8gK7hIUwT6mYzTk=
Ключ, который я сгенерировал на этом сайте, имеет...