예제 #1
0
        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));
        }
예제 #3
0
        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();
        }
예제 #4
0
        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);
        }
예제 #5
0
        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);
            }
        }
예제 #6
0
 public FormRSA()
 {
     InitializeComponent();
     algorithm = new RSAAlgorithm();
 }