Encrypt() 공개 메소드

Encrypts the specified plain text to a byte array.
public Encrypt ( byte plaintext ) : byte[]
plaintext byte The plain text to encrypt.
리턴 byte[]
        public void Constructor(DPAPIKeyType keyType)
        {
            string plainText = GenerateClearText();

            var engine = new DPAPIEngine(keyType);

            string encrypted = engine.Encrypt(plainText);

            string decrypted = engine.Decrypt(encrypted);

            Assert.NotEqual(plainText, encrypted);
            Assert.NotEqual(encrypted, decrypted);
            Assert.Equal(plainText, decrypted);
        }
        public void SetEntropyString(DPAPIKeyType keyType)
        {
            string plainText = GenerateClearText();

            var engine = new DPAPIEngine(keyType)
                .SetEntropy("myEntropy");

            string encrypted = engine.Encrypt(plainText);

            string decrypted = engine.Decrypt(encrypted);

            Assert.NotEqual(plainText, encrypted);
            Assert.NotEqual(encrypted, decrypted);
            Assert.Equal(plainText, decrypted);
        }
        public void SetEntropySecureString(DPAPIKeyType keyType)
        {
            string plainText = GenerateClearText();

            var entropy = new SecureString();
            foreach (char ch in "myEntropy")
            {
                entropy.AppendChar(ch);
            }

            var engine = new DPAPIEngine(keyType)
                .SetEntropy(entropy);

            string encrypted = engine.Encrypt(plainText);

            string decrypted = engine.Decrypt(encrypted);

            Assert.NotEqual(plainText, encrypted);
            Assert.NotEqual(encrypted, decrypted);
            Assert.Equal(plainText, decrypted);
        }
        public void SetEncoding(DPAPIKeyType keyType, Encodings encodingType)
        {
            Encoding encoding = null;

            switch (encodingType)
            {
                    //case Encodings.None:
                case Encodings.ASCII :
                    encoding = Encoding.ASCII;
                    break;
                case Encodings.UTF7 :
                    encoding = Encoding.UTF7;
                    break;
                case Encodings.UTF8 :
                    encoding = Encoding.UTF8;
                    break;
            }

            var engine = new DPAPIEngine(keyType)
                .SetEncoding(encoding);

            byte[] plainText = encoding.GetBytes(GenerateClearText());

            byte[] encrypted = engine.Encrypt(plainText);

            byte[] decrypted = engine.Decrypt(encrypted);

            Assert.NotEqual(plainText, encrypted);
            Assert.NotEqual(encrypted, decrypted);
            Assert.Equal(plainText, decrypted);
        }