public void EncryptAndDecryptDataUsingRSACertificate()
        {
            var certificate = new X509Certificate2(X509Certificate2.CreateFromSignedFile(_testCertificate));

            var encriptedText = CryptographHelper.RsaEncrypt(_textToEncrypt, certificate);
            var decriptedText = CryptographHelper.RsaDecrypt(encriptedText, certificate);

            Assert.IsNotNull(encriptedText);
            Assert.IsNotNull(decriptedText);
            Assert.AreEqual(_textToEncrypt, decriptedText);
        }
        public void EncryptAndDecryptDataUsingRSAKeys()
        {
            var publicKey  = "123";
            var privateKey = "123";

            var encriptedText = CryptographHelper.RsaEncrypt(_textToEncrypt, publicKey);
            var decriptedText = CryptographHelper.RsaDecrypt(encriptedText, privateKey);

            Assert.IsNotNull(encriptedText);
            Assert.IsNotNull(decriptedText);
            Assert.AreEqual(_textToEncrypt, decriptedText);
        }
예제 #3
0
        /// <summary>
        /// Validate database user password
        /// </summary>
        public void ValidateUserCredential(string password)
        {
            //Validates user password if it was provided
            if (UserExtraInfo.AccountTypeName == AccountType.SSOUser.ToString())
            {
                if (string.IsNullOrEmpty(password))
                {
                    Validation.Results.Add(new ValidationResult("Error: EncriptedPassword is null or empty"));
                }

                if (LoginExpirationDate.HasValue && LoginExpirationDate < DateTime.Now)
                {
                    Validation.Results.Add(new ValidationResult("Error: Login account expired"));
                }

                if (string.IsNullOrEmpty(WebSignature))
                {
                    Validation.Results.Add(new ValidationResult("Error: WebSignature is null or empty"));
                }

                if (!string.IsNullOrEmpty(password) &&
                    !string.IsNullOrEmpty(WebSignature))
                {
                    password = CryptographHelper.RijndaelDecrypt(password, CommonConsts.CommonPassword);

                    //Creates the password to decrypt PrivateKeys
                    var prefix = CommonResource.GetString("PassNumbers") + CommonResource.GetString("PassSpecialChars");
                    var pass   = prefix + CommonResource.GetString("PassText") + prefix;

                    var xmlPrivateKey         = CryptographHelper.RijndaelDecrypt(WebSignatureRsaKey.PrivateKey.GetDescription(), pass);
                    var clearTextWebSignature = CryptographHelper.RsaDecrypt(WebSignature, xmlPrivateKey);

                    if (password != clearTextWebSignature)
                    {
                        Validation.Results.Add(new ValidationResult("Error: Password mismatch."));
                    }
                }
            }
        }