Need help on password-encrypted key used for signing.

Last post 09-01-2008 8:13 AM by bhadelia.imran. 2 replies.

Sort Posts:

  • Need help on password-encrypted key used for signing.

    09-01-2008, 1:00 AM
    • Contributor
      2,861 point Contributor
    • bhadelia.imran
    • Member since 08-04-2008, 2:59 AM
    • India
    • Posts 477

    Hello Friends,

    I have one project [out-sourced] which ask me for "The project includes a password-encrypted key used for signing".

    Its window application having 5-6 sub project and its in Orcas., while loading the project its show me the dialouge to enter passoword, if I escape then while building application it ask for same and build gets failed, with error Error 1 Importing key file "abc.bbc.Data.pfx" was canceled. [as I press escape on dialouge box]

    Any comment any suggession any solutions?

     

    Imran
    [MCTS]
    Born to fly High
    http://knowledgebaseworld.blogspot.com/
  • Re: Need help on password-encrypted key used for signing.

    09-01-2008, 6:31 AM
    • Member
      264 point Member
    • saminathan.mca
    • Member since 08-22-2008, 7:33 AM
    • Erode
    • Posts 47

     string l_TempPassword = CryptorEngine.Encrypt(

    txtPassword.Text, true);

     

    public class CryptorEngine
        {
            /// <summary>
            /// Encrypt a string using dual encryption method. Return a encrypted cipher Text
            /// </summary>
            /// <param name="toEncrypt">string to be encrypted</param>
            /// <param name="useHashing">use hashing? send to for extra secirity</param>
            /// <returns></returns>
            public static string Encrypt(string toEncrypt, bool useHashing)
            {
                byte[] keyArray;
                byte[] toEncryptArray = UTF8Encoding.UTF8.GetBytes(

    toEncrypt);

               // System.Configuration.AppSettingsReader settingsReader = new AppSettingsReader();
                // Get the key from config file
             //   string key = (string)settingsReader.GetValue("rakhicrypto", typeof(String));
                string key = "rakhicrypto";
                //System.Windows.Forms.MessageBox.Show(key);
                if (useHashing)
                {
                    MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();
                    keyArray = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(key));
                    hashmd5.Clear();
                }
                else
                    keyArray = UTF8Encoding.UTF8.GetBytes(key);

                TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();
                tdes.Key = keyArray;
                tdes.Mode = CipherMode.ECB;
                tdes.Padding = PaddingMode.PKCS7;

                ICryptoTransform cTransform = tdes.CreateEncryptor();
                byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
                tdes.Clear();
                return Convert.ToBase64String(resultArray, 0, resultArray.Length);
            }
            /// <summary>
            /// DeCrypt a string using dual encryption method. Return a DeCrypted clear string
            /// </summary>
            /// <param name="cipherString">encrypted string</param>
            /// <param name="useHashing">Did you use hashing to encrypt this data? pass true is yes</param>
            /// <returns></returns>
            public static string Decrypt(string cipherString, bool useHashing)
            {
                byte[] keyArray;
                byte[] toEncryptArray = Convert.FromBase64String(cipherString);

               // System.Configuration.AppSettingsReader settingsReader = new AppSettingsReader();
                //Get your key from config file to open the lock!
                //string key = (string)settingsReader.GetValue("rakhicrypto", typeof(String));
                string key = "rakhicrypto";
                if (useHashing)
                {
                    MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();
                    keyArray = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(key));
                    hashmd5.Clear();
                }
                else
                    keyArray = UTF8Encoding.UTF8.GetBytes(key);

                TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();
                tdes.Key = keyArray;
                tdes.Mode = CipherMode.ECB;
                tdes.Padding = PaddingMode.PKCS7;

                ICryptoTransform cTransform = tdes.CreateDecryptor();
                byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);

                tdes.Clear();
                return UTF8Encoding.UTF8.GetString(resultArray);
            }
        }

    Thanks
    Saminathan.N
  • Re: Need help on password-encrypted key used for signing.

    09-01-2008, 8:13 AM
    • Contributor
      2,861 point Contributor
    • bhadelia.imran
    • Member since 08-04-2008, 2:59 AM
    • India
    • Posts 477

    Hi,

    Thanks Saminathan for the reply,

    But I dont think this is the solution that I am looking for, When I open the solution at that time its asking for password.

    What I need is to remove that password dialouge box.

    Imran
    [MCTS]
    Born to fly High
    http://knowledgebaseworld.blogspot.com/
Page 1 of 1 (3 items)