コード例 #1
0
        public void RsaDecryptBytesWithKey()
        {
            // Arrange
            CryptographyFactory f = new CryptographyFactory();

            // Act
            byte[] inputDataBytes = Convert.FromBase64String("uZj8Rm8xW0ISZICUKeQnvNGTMaG81zyhMG8f8DmThs4uTegvWYI0q6JPg1jj0Y+IsQSZHkv/XGLNUJSKrrwnkQYuS90a3OkCoqFiLw8HQnni07bp9TkzDIRQWN+RkZC+7yhIHpQvdQZYl6CSjs3/LaD+LIXHObyXvjMwXLl803I=");
            System.Security.Cryptography.RSAParameters rsaParameters = new System.Security.Cryptography.RSAParameters
            {
                D  = Convert.FromBase64String("fJY0+ECA7KN+RYl0qNsN/mwW2mVndFUTgXZ+CIfGleayMq2R5Y5TzngExcwHaYv9m99s6n9M9c+aDP33RB542z4q2OFgrucbeTKAwRhJlbOYNuLGDuCPmcejPy51JNginjkOtw31+Pn7QinMpgwNG+5n7aQrQwTi2jLI5KUoEpU="),
                DP = Convert.FromBase64String("EJGDjg0DYMTwU8EGNztrqOriZWFvHKidBZj6C0PUo6nx54DzBG9TdNaGj+o0zkUA6cXzf4x1jHYqV+yzG5Njmw=="),
                DQ = Convert.FromBase64String("GiRgLL/RiYS793OD5u/rcw6mYUXIw5bW42krYR2gV7JVrVOi2r7nHNV65StGwmfhwPNnDqwHDefVVFXSxu+O6Q=="),

                Exponent = Convert.FromBase64String("AQAB"),
                InverseQ = Convert.FromBase64String("N/6gNxkobfLf5MaqWwX9Y7hu4UT+urVWC6CASgYwmqsTxBZGGsizVZ3ocq1A814Lo9S+REgKYFYdqh6agXEYOQ=="),
                Modulus  = Convert.FromBase64String("wmkOrKR16oKeDz+9mUqCUOw9jdwDDusrzHH7CEtuWt2XmC6Yu5fG+fh5QquLLF1aC9fyKbr126NsJ2zPbSkejI7grUghDC71D25PCz8sY3bpbMhzXDr8XxM4WSvg3edsSsOhvYzkRa+yZkhWxiaQ+Z0Vb0tTYNyRPi34YLmQZCU="),

                P = Convert.FromBase64String("zvIZ1lx6Qa++2cQVrNguqNbWMziSRrtWUcWISBrtYuzm8aYOm10JbKdq0oRBZspwDyrAyvajGbLBmi2FvwlHZw=="),
                Q = Convert.FromBase64String("8H5JWPl4W6THX5Fw7HHta7x+fOpeV6q1MU4Bzpb6ld9rphD3v6r5F06dojdWTdujv8o94ezx1tm84TWVOpX8kw==")
            };
            byte[] plainTextBytes = f.Decrypt(inputDataBytes, rsaParameters);

            string resultBase64 = System.Text.Encoding.UTF8.GetString(plainTextBytes);

            Console.WriteLine("Result = [{0}]", resultBase64);

            // Assert
            Assert.AreEqual("Hello world", resultBase64);
        }
コード例 #2
0
        public void AESDecryptBytesWithKeyIV()
        {
            // Arrange
            CryptographyFactory f = new CryptographyFactory();

            // Act
            byte[] keyBytes    = Convert.FromBase64String("yfNvMXVJMJXhbgIKtjroQkrYhfXpyjhK0TP5xYdJVPk=");
            byte[] ivBytes     = Convert.FromBase64String("7/T4oOkXvkoORPFLAPg13w==");
            byte[] cipherBytes = Convert.FromBase64String("dnd6ee2g5NlUFTErWNVGng==");

            //byte[] hashBytes = f.Decrypt(cipherBytes, keyBytes, ivBytes);
            //string result = System.Text.Encoding.UTF8.GetString(hashBytes);
            string result = f.Decrypt(cipherBytes, keyBytes, ivBytes);;

            // Assert
            Assert.AreEqual("Hello world", result);
        }