Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. 10 digit Crypted Value

10 digit Crypted Value

Scheduled Pinned Locked Moved C#
question
8 Posts 5 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Enobong Adahada
    wrote on last edited by
    #1

    pls i want to generate a ten digit crypted value from a 4 digit number, pls how do i get it done. thank you.

    OriginalGriffO S 2 Replies Last reply
    0
    • E Enobong Adahada

      pls i want to generate a ten digit crypted value from a 4 digit number, pls how do i get it done. thank you.

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      Sorry, but you will have to explain your requirement rather more clearly. You could use any method you like to generate a ten digit code from a 4 digit, so that it could be converted back, but what are you trying to achieve?

      Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      E 1 Reply Last reply
      0
      • E Enobong Adahada

        pls i want to generate a ten digit crypted value from a 4 digit number, pls how do i get it done. thank you.

        S Offline
        S Offline
        Sathesh Sakthivel
        wrote on last edited by
        #3

        What code you have written? If it is showing any error then put your error we will help you.

        Regards, Sathesh. The best way to express one's gratitude to the Divine is to feel simply Happy..

        E 1 Reply Last reply
        0
        • OriginalGriffO OriginalGriff

          Sorry, but you will have to explain your requirement rather more clearly. You could use any method you like to generate a ten digit code from a 4 digit, so that it could be converted back, but what are you trying to achieve?

          Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

          E Offline
          E Offline
          Enobong Adahada
          wrote on last edited by
          #4

          My plaintex is a four digit xters, after encryption i get a 24 digit set of xters, i want to limit the encrypted values to just 10 digits, is that posible? if so pls how? thank you.

          OriginalGriffO Y 2 Replies Last reply
          0
          • S Sathesh Sakthivel

            What code you have written? If it is showing any error then put your error we will help you.

            Regards, Sathesh. The best way to express one's gratitude to the Divine is to feel simply Happy..

            E Offline
            E Offline
            Enobong Adahada
            wrote on last edited by
            #5

            here is my code: public static string iEncrypt(string plainText, string passPhrase, string saltValue, string HashAlgorithm, int passwordIterations, string initVector, int KeySizes) { byte[] initVectorBytes = Encoding.ASCII.GetBytes(initVector); byte[] saltValueBytes = Encoding.ASCII.GetBytes(saltValue); byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText); PasswordDeriveBytes password = new PasswordDeriveBytes(passPhrase, saltValueBytes, HashAlgorithm, passwordIterations); byte[] keyBytes = password.GetBytes(KeySizes / 8); RijndaelManaged symmetricaKey = new RijndaelManaged(); symmetricaKey.Mode = CipherMode.CBC; ICryptoTransform encryptor = symmetricaKey.CreateEncryptor(keyBytes, initVectorBytes); MemoryStream memoryStream = new MemoryStream(); CryptoStream cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write); cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length); cryptoStream.FlushFinalBlock(); byte[] cipherTextBytes = memoryStream.ToArray(); memoryStream.Close(); cryptoStream.Close(); string cipherText = Convert.ToBase64String(cipherTextBytes); return cipherText; } static void Main(string[] args) { //string plainText="Hello World!"; string plainText; string passPhrase = "Pas5pr@se"; //string passPhrase = "123456789"; //string saltValue = "123456789";//s@ltValue"; string saltValue = "s@ltValue"; string hashAlgorithm = "SHA1"; int passwordIterations = 1; //string initVector = "abcdefghijklmnop";//@1B2c3D4e5F6g7H8"; string initVector = "@1B2c3D4e5F6g7H8"; int keySize = 64;//256; //Console.WriteLine(string.Format("Plaintext : {0}", plainText)); Console.WriteLine(string.Format("Type Plaintext : ")); plainText= Console.ReadLine(); string cipherText = dEncrypt.iEncrypt(plainText, passPhrase, saltValue, hashAlgorithm, passwordIterations, initVector, keySize); Console.WriteLine(string.Format("Encrypted : {0}", cipherText)); }

            N 1 Reply Last reply
            0
            • E Enobong Adahada

              My plaintex is a four digit xters, after encryption i get a 24 digit set of xters, i want to limit the encrypted values to just 10 digits, is that posible? if so pls how? thank you.

              OriginalGriffO Offline
              OriginalGriffO Offline
              OriginalGriff
              wrote on last edited by
              #6

              Looking briefly at your code reply on the other thread, this is for password matching? If so, then just do what everyone else does - don't use encryption, use hashing. MD5 or SHA will give you a 128bit hash of a password which you can store and check against. That is what most do - since it is a hash, it is not reversible (you don't need a key to generate it, just the password) and it can't be reverse engineered to get the password (particularly for SHA, MD5 can be revwerse engineeered in some circumstances). It is also a good idea to include the UserId with the password before hashing, so that two users with the same password don't generate the same hash...

              Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.

              "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
              "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

              1 Reply Last reply
              0
              • E Enobong Adahada

                here is my code: public static string iEncrypt(string plainText, string passPhrase, string saltValue, string HashAlgorithm, int passwordIterations, string initVector, int KeySizes) { byte[] initVectorBytes = Encoding.ASCII.GetBytes(initVector); byte[] saltValueBytes = Encoding.ASCII.GetBytes(saltValue); byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText); PasswordDeriveBytes password = new PasswordDeriveBytes(passPhrase, saltValueBytes, HashAlgorithm, passwordIterations); byte[] keyBytes = password.GetBytes(KeySizes / 8); RijndaelManaged symmetricaKey = new RijndaelManaged(); symmetricaKey.Mode = CipherMode.CBC; ICryptoTransform encryptor = symmetricaKey.CreateEncryptor(keyBytes, initVectorBytes); MemoryStream memoryStream = new MemoryStream(); CryptoStream cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write); cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length); cryptoStream.FlushFinalBlock(); byte[] cipherTextBytes = memoryStream.ToArray(); memoryStream.Close(); cryptoStream.Close(); string cipherText = Convert.ToBase64String(cipherTextBytes); return cipherText; } static void Main(string[] args) { //string plainText="Hello World!"; string plainText; string passPhrase = "Pas5pr@se"; //string passPhrase = "123456789"; //string saltValue = "123456789";//s@ltValue"; string saltValue = "s@ltValue"; string hashAlgorithm = "SHA1"; int passwordIterations = 1; //string initVector = "abcdefghijklmnop";//@1B2c3D4e5F6g7H8"; string initVector = "@1B2c3D4e5F6g7H8"; int keySize = 64;//256; //Console.WriteLine(string.Format("Plaintext : {0}", plainText)); Console.WriteLine(string.Format("Type Plaintext : ")); plainText= Console.ReadLine(); string cipherText = dEncrypt.iEncrypt(plainText, passPhrase, saltValue, hashAlgorithm, passwordIterations, initVector, keySize); Console.WriteLine(string.Format("Encrypted : {0}", cipherText)); }

                N Offline
                N Offline
                Not Active
                wrote on last edited by
                #7

                Please remember to use the pre tags when posting code snippets.


                I know the language. I've read a book. - _Madmatt

                1 Reply Last reply
                0
                • E Enobong Adahada

                  My plaintex is a four digit xters, after encryption i get a 24 digit set of xters, i want to limit the encrypted values to just 10 digits, is that posible? if so pls how? thank you.

                  Y Offline
                  Y Offline
                  Yvan Rodrigues
                  wrote on last edited by
                  #8

                  What method of encryption are you using that is resulting the the 24 character result? What factors made you choose this method of encryption? Why are you encypting the value? Do you need to be able to decrypt the result in order to obtain the original value? Are there any transport considerations e.g. 7-bit transmission restriction? Need more info to help.

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups