1234567891011121314151617181920212223242526272829303132 |
- using System.Diagnostics;
- using System.Security.Cryptography;
- using System.Text;
- using PCC.App.Security;
- namespace PCC.Pocs.Pocs
- {
- internal static class RsaUtilityPoc
- {
- public static void RunPoc()
- {
- var (pub1, pri1) = RsaUtility.GeneratePKCS1(4096); // sender
- var (pub2, pri2) = RsaUtility.GeneratePKCS1(4096); // rec
- var rsaPub1 = RsaUtility.FromPKCS1PublicKey(pub1);
- var rsaPri1 = RsaUtility.FromPKCS1PrivateKey(pri1);
- var rsaPub2 = RsaUtility.FromPKCS1PublicKey(pub2);
- var rsaPri2 = RsaUtility.FromPKCS1PrivateKey(pri2);
- var rawText = RandomNumberGenerator.GetString(new[] { 'C', 'D' }, RandomNumberGenerator.GetInt32(10)) + "Brrr汉字Brrr:" + RandomNumberGenerator.GetString(new[] { 'A', 'B' }, 1024);
- var rawBytes = Encoding.UTF8.GetBytes(rawText);
- var encBytes = RsaUtility.EncryptAndSignature(rsaPub2, rawBytes, rsaPri1);
- var decBytes = RsaUtility.DecryptAndVerifySignature(rsaPri2, encBytes, rsaPub1);
- var decText = Encoding.UTF8.GetString(decBytes);
- var success = rawText == decText;
- }
- }
- }
|