Пример #1
0
        static void Main(string[] args)
        {
            LogSign logSign = new LogSign();

            logSign.starupScreen();
            Console.ReadKey();
        }
Пример #2
0
        public string RsaEncryptWithPublic(string sessionKey, string username, string pathOfCert)
        {
            string pathOfCryptedSessionKeyFile;

            X509Certificate2 x509 = new X509Certificate2();

            //Create X509Certificate2 object from .pem file.

            byte[] rawData = LogSign.ReadFile(pathOfCert);

            x509.Import(rawData);
            var cert = new Org.BouncyCastle.X509.X509CertificateParser().ReadCertificate(x509.GetRawCertData());

            var bytesToEncrypt = Encoding.UTF8.GetBytes(sessionKey);
            var encryptEngine  = new Pkcs1Encoding(new RsaEngine());
            var keyParameter   = cert.GetPublicKey();

            encryptEngine.Init(true, keyParameter);
            var encrypted = Convert.ToBase64String(encryptEngine.ProcessBlock(bytesToEncrypt, 0, bytesToEncrypt.Length));


            pathOfCryptedSessionKeyFile = AppDomain.CurrentDomain.BaseDirectory + username + "\\" + DateTime.Now.ToString("hh-mm-ss-dd-MM-yyyy") + "cryptedSessionKeyFile.txt"; //mozda ne potrebas .pem format,vidjeti u toku rada!!!

            /*using (FileStream fs = File.Create(pathOfCryptedSessionKeyFile)) //upis kriptovanog sesijskog kljuca u file!
             * {
             *  fs.Write(Convert.FromBase64String(encrypted), 0, Convert.FromBase64String(encrypted).Length);
             * }*/

            File.WriteAllText(pathOfCryptedSessionKeyFile, encrypted);

            return(encrypted);//za sad nepotrebno
        }