public void ValidateWithInvalidHashAlgorithm()
        {
            Exception e = null;

            JwtManager.RsJwt sJwt = new JwtManager.RsJwt
            {
                KeySize    = HashKeySize(),
                PrivateKey = PrivateKey
            };
            JwtManager.RsJwt vJwt = new JwtManager.RsJwt
            {
                KeySize   = (JwtManager.Helpers.KeySize) 555,
                PublicKey = PublicKey
            };

            try
            {
                string data       = "{a:1,b:2}";
                string signedData = sJwt.Sign(data);
                Assert.IsNull(e, "An exception should not be thrown here");
                string validatedData = vJwt.Validate(signedData);
            }
            catch (Exception ex)
            {
                e = ex;
            }

            Assert.IsNotNull(e, "An exception should be thrown");
            Assert.AreEqual(e.Message, "Given key size is not valid.");
        }
        public void ValidateOtherPublicKey1()
        {
            Exception e = null;

            JwtManager.RsJwt sJwt = new JwtManager.RsJwt
            {
                KeySize    = HashKeySize(),
                PrivateKey = PrivateKey
            };
            JwtManager.RsJwt vJwt = new JwtManager.RsJwt
            {
                KeySize    = HashKeySize(),
                PrivateKey = PrivateKey
            };

            try
            {
                string data       = "{a:1,b:2}";
                string signedData = sJwt.Sign(data);
                Assert.IsNull(e, "An exception should not be thrown here");
                string validatedData = vJwt.Validate(signedData);
            }
            catch (Exception ex)
            {
                e = ex;
            }

            Assert.IsNotNull(e, "An exception should be thrown");
        }
        public void SignData()
        {
            JwtManager.RsJwt jwt = new JwtManager.RsJwt
            {
                KeySize    = HashKeySize(),
                PrivateKey = PrivateKey
            };

            string data       = "{a:1,b:2}";
            string signedData = jwt.Sign(data);

            Assert.IsTrue(signedData != null, "Object should not be null");
        }
        public void ValidateData()
        {
            string data = "{a:1,b:2}";

            JwtManager.RsJwt signJwt = new JwtManager.RsJwt
            {
                KeySize    = HashKeySize(),
                PrivateKey = PrivateKey
            };
            string signedData = signJwt.Sign(data);

            JwtManager.RsJwt jwt = new JwtManager.RsJwt
            {
                KeySize   = HashKeySize(),
                PublicKey = PublicKey
            };
            string validatedData = jwt.Validate(signedData);

            Assert.AreEqual(data, validatedData, "Signed data should match the original data");
        }
        public void ValidateInvalidPublicKey()
        {
            Exception e = null;

            JwtManager.RsJwt jwt = new JwtManager.RsJwt
            {
                KeySize   = HashKeySize(),
                PublicKey = PublicKey + "a"
            };

            try
            {
                string data          = "{a:1,b:2}";
                string signedData    = jwt.Sign(data);
                string validatedData = jwt.Validate(signedData);
            }
            catch (Exception ex)
            {
                e = ex;
            }

            Assert.IsNotNull(e, "An exception should be thrown");
        }
Пример #6
0
        public void SignDataWithInvalidHashAlgorithm()
        {
            Exception e = null;

            JwtManager.RsJwt jwt = new JwtManager.RsJwt
            {
                KeySize    = (JwtManager.Enums.KeySize) 555,
                PrivateKey = PrivateKey
            };

            try
            {
                string data       = "{a:1,b:2}";
                string signedData = jwt.Sign(data);
            }
            catch (Exception ex)
            {
                e = ex;
            }

            Assert.IsNotNull(e, "An exception should be thrown");
            Assert.AreEqual(e.Message, "Invalid values for algorithm or size.");
        }
        public void SignDataWithInvalidHashAlgorithm()
        {
            Exception e = null;

            JwtManager.RsJwt jwt = new JwtManager.RsJwt
            {
                KeySize    = (JwtManager.Helpers.KeySize) 555,
                PrivateKey = PrivateKey
            };

            try
            {
                string data       = "{a:1,b:2}";
                string signedData = jwt.Sign(data);
            }
            catch (Exception ex)
            {
                e = ex;
            }


            Assert.IsNotNull(e, "An exception should be thrown");
            Assert.AreEqual(e.Message, "Signer SHA555WITHRSA not recognised.");
        }
        public void InitClass()
        {
            JwtManager.RsJwt jwt = new JwtManager.RsJwt();

            Assert.IsTrue(jwt != null, "Object should not be null");
        }