Пример #1
0
        /// <summary>
        /// 輸出加密文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonExportEncryptFile_Click(object sender, EventArgs e)
        {
            SaveFileDialog dialog = new SaveFileDialog();

            dialog.Filter = "*.lic|";
            dialog.Title  = "Save Encrypted File";

            //預設檔案名稱和副檔名
            dialog.FileName   = "License";
            dialog.DefaultExt = "lic";

            //加密公鑰路徑
            string publicKey = $"{ this.textBoxEncryptKeyPath.Text}";

            var EncryptTxet = RSAKit.Encrypt(this.textBoxDecryptContent.Text, publicKey);

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                using (StreamWriter sw = new StreamWriter(dialog.FileName))
                {
                    sw.WriteLineAsync(EncryptTxet);
                }

                //複製私鑰放到和License一起
                var CopyPrivateKey = Path.Combine(Path.GetDirectoryName(dialog.FileName), RSAKit.privateKeyFileName);
                File.Copy(this.textBoxEncryptKeyPath.Text, CopyPrivateKey, true);
            }
            MessageBox.Show("儲存完畢", "提示");
        }
Пример #2
0
        public void EncryptTest()
        {
            BigInteger expected = new BigInteger(128);
            BigInteger input    = new BigInteger(2);

            kit.E = BigInteger.Parse("7");
            kit.P = BigInteger.Parse("17");
            kit.Q = BigInteger.Parse("11");
            kit.N = kit.Create_n();
            BigInteger result = kit.Encrypt(input);

            Assert.AreEqual(expected, result);
        }