public void ExportImportEncryptTest() { byte[] toEncrypt = new byte[] { 1, 2, 3, 4 }; string filePath = @".\TestPublic.Key"; try { File.Delete(filePath); } catch (Exception) { } ManagedRSAEncryption util = new ManagedRSAEncryption(); util.ExportPublicKeytoFile(TestProvider, TestKeyName, filePath); Assert.IsTrue(File.Exists(filePath)); byte[] encryptedBytes = util.EncryptWithFileKey(filePath, toEncrypt); Assert.IsNotNull(encryptedBytes); byte[] decryptedBytes = util.DecryptWithLocalKey(TestProvider, TestKeyName, encryptedBytes); Assert.AreEqual(System.Convert.ToBase64String(toEncrypt), System.Convert.ToBase64String(decryptedBytes)); try { File.Delete(filePath); } catch (Exception) { } }
protected override void ProcessRecord() { ManagedRSAEncryption managedRSA = new ManagedRSAEncryption(); managedRSA.ExportPublicKeytoFile(ProviderName, KeyName, FilePath, FileFormat); }