Chào mừng!

Bằng cách đăng ký với chúng tôi, bạn sẽ có thể thảo luận, chia sẻ và nhắn tin riêng tư với các thành viên khác trong cộng đồng của chúng tôi.

Đăng ký ngay!
  • Chào Khách,
    Bạn cần liên hệ với admin ??? ZALO & TELEGRAM

Cần giúp Tạo output file pdf sau khi ký số SHA256 với private_key

Tham gia
29/3/23
Bài viết
1
Lượt Thích
0
Coins
1,000
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
 
Top Bottom
AdBlock Detected

We get it, advertisements are annoying!

Sure, ad-blocking software does a great job at blocking ads, but it also blocks useful features of our website. For the best site experience please disable your AdBlocker.

I've Disabled AdBlock
No Thanks