private void btnRandKey_Click(object sender, EventArgs e) { RSAAlgorithm r = new RSAAlgorithm(); byte[] rand = r.GenerateRandomKey(); UInt32 key = BitConverter.ToUInt32(rand, 0); txtE.Text = key.ToString(); }
public void SignVerifyRSA(RSAAlgorithm algorithm) { HashAlgorithmName hashAlgorithm = GetHashAlgorithmNameFromCoseAlgorithm((int)algorithm); byte[] coseMessageBytes = CoseSign1Message.Sign(s_sampleContent, RSAKey, hashAlgorithm); CoseSign1Message msg = CoseMessage.DecodeSign1(coseMessageBytes); Assert.True(msg.Verify(RSAKey)); }
private void btnDekript_Click(object sender, EventArgs e) { RSAAlgorithm r = new RSAAlgorithm(UInt32.Parse(txtP.Text), UInt32.Parse(txtQ.Text), UInt32.Parse(txtE.Text)); int ulaz = int.Parse(txtUlaz.Text); byte[] izlaz = r.Decrypt(BitConverter.GetBytes(ulaz)); uint cr = BitConverter.ToUInt32(izlaz, 0); txtKript.Text = cr.ToString(); }
public void RSAGenerateTest() { RSAAlgorithm instance = Factory.Create <RSAAlgorithm>(KeyAlgorithm.RSA, KeyOperation.Generate); const short KEY_LENGTH = 2048; Key privateKey = instance.generateKey(KEY_LENGTH); Assert.IsInstanceOfType(privateKey, typeof(RSAPrivateKey)); Assert.AreEqual(privateKey.Length, KEY_LENGTH); Assert.IsInstanceOfType((privateKey as RSAPrivateKey).PublicKey, typeof(RSAPublicKey)); Assert.AreEqual((privateKey as RSAPrivateKey).PublicKey.Length, KEY_LENGTH); }
public static byte[] AsymmetricEncrypt([NotNull] X509Certificate2 certificate, [NotNull] byte[] data, RSASettings settings = null) { if (data.Length == 0) { return(null); } IAsymmetricAlgorithm asymmetric = null; try { System.Security.Cryptography.RSA algorithm = certificate.GetPublicEncryptor <System.Security.Cryptography.RSA>(); asymmetric = new RSAAlgorithm <System.Security.Cryptography.RSA>(algorithm); return(AsymmetricEncrypt(asymmetric, data, settings)); } finally { ObjectHelper.Dispose(ref asymmetric); } }
public FormRSA() { InitializeComponent(); algorithm = new RSAAlgorithm(); }