Пример #1
0
        public CommandsContainer(Options options,
                                 IMainForm mainForm,
                                 IEnvironmentHelper environmentHelper,
                                 IMessageHelper messageHelper,
                                 IFormFactory formFactory)
        {
            var         primeTest      = new RabinMillerTest(20);
            var         primeGenerator = new PrimeGenerator(primeTest);
            var         keyGenerator   = new KeyGenerator(new RsaKeyGenerator(), primeGenerator);
            var         fileUnifier    = new FileUnifier();
            var         zipAlgorithm   = new ZipAlgorithm(environmentHelper);
            IRsaFactory rsaFactory     = new RsaFactory(new FileFactory(0), options, environmentHelper, zipAlgorithm);

            AboutProgramCommand = new AboutProgramCommand(formFactory, environmentHelper);
            CipherCommand       = new CipherCommand(this, mainForm.FilesView, formFactory, fileUnifier, environmentHelper, options,
                                                    rsaFactory,
                                                    messageHelper);
            DecipherCommand = new DecipherCommand(this, mainForm.FilesView, rsaFactory, environmentHelper, formFactory,
                                                  messageHelper,
                                                  fileUnifier);
            ExitCommand             = new ExitCommand();
            GenerateKeysCommand     = new GenerateKeysCommand(keyGenerator, options, formFactory, messageHelper);
            refreshDirectoryCommand = new RefreshDirectoryCommand(messageHelper);
            toUpperFolderCommand    = new ToUpperFolderCommand(messageHelper);
            changeLanguageCommand   = new ChangeLanguageCommand(options);
            var cryptoViews = new ICryptoView[] { mainForm.MainMenu, mainForm.ToolBar, mainForm.FilesView };

            RefreshCryptoViewsCommand = new RefreshCryptoViewsCommand(mainForm.FilesView, cryptoViews);
        }
 public void SetUp()
 {
     DeleteTestFolder();
     Directory.CreateDirectory(testFolder);
     fileFactory       = new Mock <IFileFactory>();
     options           = new Options();
     environmentHelper = new Mock <IEnvironmentHelper>();
     zipAlgorithm      = new Mock <IZipAlgorithm>();
     rsaFactory        = new RsaFactory(fileFactory.Object, options, environmentHelper.Object, zipAlgorithm.Object);
 }
Пример #3
0
        public void EncryptDecrypt_R2048_JSON_Test()
        {
            var key      = RsaKeyGenerator.Generate(AsymmetricKeyMode.Both, RsaKeySize.L2048, RsaKeyFormat.JSON);
            var function = RsaFactory.Create(key);

#if NET451 || NET452
            var cipherVal = function.EncryptByPublicKey("image", true);
            var originVal = function.DecryptByPrivateKey(cipherVal.CipherData, true);
#else
            var cipherVal = function.EncryptByPublicKey("image", RSAEncryptionPadding.OaepSHA1);
            var originVal = function.DecryptByPrivateKey(cipherVal.CipherData, RSAEncryptionPadding.OaepSHA1);
#endif
            Assert.Equal("image", originVal.GetOriginalDataDescriptor().GetString());
        }