Beispiel #1
0
            internal void DecryptAccessIDAndSecretKey()
            {
                DecryptedAccessID  = SimpleAES4String.Decrypt(AccessID, KEK);
                DecryptedSecretKey = SimpleAES4String.Decrypt(SecretKey, KEK);

                KEK = KEK.HideString(1, true);  // Config 조회 시 가리는 효과.
            }
Beispiel #2
0
        public void 암호화_복호화_테스트()
        {
            const String KEY        = "test-key";
            const String PLAIN_TEXT = "O5X3j3OeNw6/uHN+J/1HY6B3zyo8EOMAisfKbzyPt4Y=";

            {
                String encrypted = SimpleAES4String.Encrypt(PLAIN_TEXT, KEY);
                String decrypted = SimpleAES4String.Decrypt(encrypted, KEY);
                Assert.IsTrue(PLAIN_TEXT == decrypted);
            }

            Assert.ThrowsException <ArgumentNullException>(() => SimpleAES4String.Encrypt(null, KEY));

            Assert.ThrowsException <ArgumentNullException>(() => SimpleAES4String.Encrypt("...", String.Empty));

            Assert.ThrowsException <ArgumentNullException>(() => SimpleAES4String.Decrypt(null, KEY));

            Assert.ThrowsException <ArgumentNullException>(() => SimpleAES4String.Decrypt("...", String.Empty));
        }
Beispiel #3
0
        private static void Main(String[] args)
        {
            Console.Write("KEK: ");
            String kekString = Console.ReadLine();

            Console.Write("Key: ");
            String keyString = Console.ReadLine();

            if (String.IsNullOrEmpty(kekString) || String.IsNullOrEmpty(keyString))
            {
                Console.WriteLine("NotCompletePut KEK or Key.");
                return;
            }

            Byte[] kekBytes = new Byte[SimpleAES4String.AES_KEY_SIZE];
            Encoding.UTF8.GetBytes(kekString).ToArray().CopyTo(kekBytes, 0);

            try
            {
                String encryptedKey = SimpleAES4String.Encrypt(keyString, kekString);
                Console.WriteLine("Encrypted Key: " + encryptedKey);

                String plainKey = SimpleAES4String.Decrypt(encryptedKey, kekString);
                if (String.CompareOrdinal(keyString, plainKey) != 0)
                {
                    Console.WriteLine("Fail Test!!!");
                    return;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: " + e.Message);
            }

            Console.WriteLine("ok.");
            Console.ReadLine();
        }