コード例 #1
0
        public void GetBytesFromValidPrefixedHexString()
        {
            string hex = "0x00FF";

            byte[] hexByte = CryptographyUtility.GetBytesFromHexString(hex);

            Assert.AreEqual(0, hexByte[0]);
            Assert.AreEqual(255, hexByte[1]);
        }
        public void GetBytesFromValidHexString()
        {
            string hex = "00FF";

            byte[] hexByte = CryptographyUtility.GetBytesFromHexString(hex);

            byte expected = 0;

            Assert.AreEqual(expected, hexByte[0]);
            expected = 255;
            Assert.AreEqual(expected, hexByte[1]);
        }
コード例 #3
0
ファイル: CreateNewKeyControl.cs プロジェクト: janeth182/ISIL
 private byte[] GetKeyBox()
 {
     if (keyBox.Text.Length > 0)
     {
         byte [] hexBytes = CryptographyUtility.GetBytesFromHexString(keyBox.Text);
         return(hexBytes);
     }
     else
     {
         return(new byte[0]);
     }
 }
コード例 #4
0
        private bool ValidateEntropy()
        {
            bool result = true;

            if (txtEntropy.TextLength < EntropySizeBase64)
            {
                result = false;
            }

            try
            {
                CryptographyUtility.GetBytesFromHexString(txtEntropy.Text);
            }
            catch
            {
                result = false;
            }
            return(result);
        }
        public void GetBytesFromInvalidCharactersHexStringThrows()
        {
            string hex = "Invalid!";

            CryptographyUtility.GetBytesFromHexString(hex);
        }
        public void GetBytesFromInvalidLengthHexStringThrowsThrows()
        {
            string hex = "0FF";

            CryptographyUtility.GetBytesFromHexString(hex);
        }
コード例 #7
0
        /// <summary>
        /// Method to generate Password Encryption Key.
        /// This method is main entry point for the application.
        /// </summary>
        public static void GeneratePasswordEncryptionKey()
        {
            try
            {
                // Code that runs on application startup
                //Common.MessagePath = Application.StartupPath + "/App_Data/Messages.xml";
                string defaultPassword = ConfigurationSettings.AppSettings["DefaultPassword"];

                if (!Directory.Exists(Properties.Resources.CryptoKeyPath))
                {
                    Directory.CreateDirectory(Properties.Resources.CryptoKeyPath);
                }
                if (!File.Exists(Properties.Resources.CryptoKeyPath + "Vestige.key"))
                {
                    using (Stream io = new FileStream(Properties.Resources.CryptoKeyPath + "Vestige.key", FileMode.Append))
                    {
                        CryptographyManager.WriteProtectedKey(io,
                                                              CryptographyManager.CreateProtectedKey(CryptographyUtility.GetBytesFromHexString("22E3CA2764D24337430C7081CAB1751CDEC4081DDB8CF64AA292583A607B4A47"), DataProtectionScope.LocalMachine));
                        io.Close();
                    }
                    //using (DataTaskManager dtManager = new DataTaskManager())
                    //{
                    //    string adminPwd = (new CryptographyManager(CryptographyProviderType.SymmetricCryptoProvider)).Encrypt(ConfigurationSettings.AppSettings["DefaultPassword"]);
                    //    string sqlQuery = string.Empty;
                    //    //sqlQuery = "IF EXISTS(SELECT * FROM User_Master WHERE UserName = '******' AND Status = 1) ";
                    //    sqlQuery += "UPDATE User_Master SET Password='******' WHERE UPPER(UserName) = 'SUPER.ADMIN' AND Status = 1 ";
                    //    //sqlQuery += "ELSE INSERT INTO User_Master(UserId, UserName, Password, FirstName, Status, CreatedBy, CreatedDate, ModifiedBy, ModifiedDate) ";
                    //    //sqlQuery += "VALUES(0, 'Admin', '" + adminPwd + "', 'Administrator', 1, 0, GETDATE(), 0, GETDATE())";
                    //    dtManager.ExecuteSqlQuery(sqlQuery);
                    //}
                }
            }
            catch (Exception ex)
            {
                throw ex;
                //Common.LogException(ex);
                //MessageBox.Show(Common.GetMessage("10002"), Common.GetMessage("10001"),
                //    MessageBoxButtons.OK, MessageBoxIcon.Error);
                //Application.Exit();
            }
        }