Kashub's Code Barn - "aaaa"

podświetlone jako sdlbasic (dodał(a) rzepson @ 2022-11-13 18:53:34)

Twoja wyszukiwarka
T-Mobile
Podświetl ten kod w:
Ostatnio dodane:
Losowe wpisy:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Security.Cryptography;
 
namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
 
        }
 
            private void btnPublic_key_Click(object sender, EventArgs e)
        {
            var cryptoServiceProvider = new RSACryptoServiceProvider(2048); //2048 - Długość klucza
            var publicKey = cryptoServiceProvider.ExportParameters(false); //Generowanie klucza publiczny
            string publicKeyString = GetKeyString(publicKey);
            lblPublic_Key.Text = publicKeyString;
 
        }
 
 
        private void btnPrivate_key_Click(object sender, EventArgs e)
        {
            var cryptoServiceProvider = new RSACryptoServiceProvider(2048); //2048 - Długość klucza
            var privateKey = cryptoServiceProvider.ExportParameters(true); //Generowanie klucza prywatnego
            string privateKeyString = GetKeyString(privateKey);
            lblPrivate_Key.Text = privateKeyString;
        }
 
        public static string GetKeyString(RSAParameters publicKey)
        {
 
            var stringWriter = new System.IO.StringWriter();
            var xmlSerializer = new System.Xml.Serialization.XmlSerializer(typeof(RSAParameters));
            xmlSerializer.Serialize(stringWriter, publicKey);
            return stringWriter.ToString();
        }
 
        private void btnEncryptiontext_Click(object sender, EventArgs e)
        {
            string tekst = textBox_text.Text;
            string encryptedText = Encrypt(tekst, publicKeyString); //Szyfrowanie za pomocą klucza publicznego
            lbl_Encryptiontxt.Text = encryptedText;
        }
 
        public static string Encrypt(string tekst, string publicKeyString)
        {
            var bytesToEncrypt = Encoding.UTF8.GetBytes(tekst);
 
            using (var rsa = new RSACryptoServiceProvider(2048))
            {
                try
                {
                    rsa.FromXmlString(publicKeyString.ToString());
                    var encryptedData = rsa.Encrypt(bytesToEncrypt, true);
                    var base64Encrypted = Convert.ToBase64String(encryptedData);
                    return base64Encrypted;
                }
                finally
                {
                    rsa.PersistKeyInCsp = false;
                }
            }
        }
    }
}
 
| Wózki dla dzieci | | Sklep z oponami | | Opony letnie | | Opony specjalne | | Sklep z artykułami RTV/AGD | | Skracacz linków | | Kody programów | | Skracacz linków | | Smutne Opisy | | Opisy na Facebooka |