Mình có đoạn code nhỏ thực hiện ký số sử dụng private key từ file p12, ký hash SHA256, hiện tại đã signhash xong nhưng chưa biết cách nào để lấy file đầu ra (output file - file sau khi ký), bạn nào có kinh nghiệm chỉ mình với ạ, mình xin hậu tạ ly cà phê
/đường dẫn file cần ký
string path = @"C:\test.pdf";
//đọc file và chuyển file đó sang dạng mảng byte[]
byte[] buff2 = File.ReadAllBytes(path);
//chuyển mảng byte sang thành phần SHA256
var hashAlgorithm = new SHA256Managed();
var hash = hashAlgorithm.ComputeHash(buff2);
// Load the P12 file containing the private key
var cert = new X509Certificate2(Server.MapPath("~/bin/Agony-1122122-22.p12"), "111111111");
// Create an RSACryptoServiceProvider object from the private key in the certificate
var privateKey = cert.GetRSAPrivateKey();
//var publicKey = cert.GetRSAPublicKey();
// Sign the hash using the private key
var signature = privateKey.SignHash(hash, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
// file đầu ra
/đường dẫn file cần ký
string path = @"C:\test.pdf";
//đọc file và chuyển file đó sang dạng mảng byte[]
byte[] buff2 = File.ReadAllBytes(path);
//chuyển mảng byte sang thành phần SHA256
var hashAlgorithm = new SHA256Managed();
var hash = hashAlgorithm.ComputeHash(buff2);
// Load the P12 file containing the private key
var cert = new X509Certificate2(Server.MapPath("~/bin/Agony-1122122-22.p12"), "111111111");
// Create an RSACryptoServiceProvider object from the private key in the certificate
var privateKey = cert.GetRSAPrivateKey();
//var publicKey = cert.GetRSAPublicKey();
// Sign the hash using the private key
var signature = privateKey.SignHash(hash, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
// file đầu ra