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. Cannot use Java generated DES Key in C#

Cannot use Java generated DES Key in C#

Scheduled Pinned Locked Moved C#
csharpjavaalgorithmshelptutorial
3 Posts 2 Posters 0 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.
  • K Offline
    K Offline
    karpolu
    wrote on last edited by
    #1

    Greetings, I am developing an application that reads a DES encrypted password generated using Java in a properties file and decrypts it, using DESCryptoServiceProvider. I am provided with the key string originally generated with Java using DES. Does anyone have an example or sample code that converts/uses a Java generated key to decrypt a Java generated password in C#? After removing the dashes, I get the "Specified key is not a valid size for this algorithm" exception. I've tried both of these lines of code and get the same error: static byte[] key = ASCIIEncoding.ASCII.GetBytes(dashKey.Replace("-", "")); OR static byte[] key = Encoding.ASCII.GetBytes(dashKey.Replace("-", "")); The error occurrs at either of the below lines of code I tried: cryptoProvider.Key = key; OR ICryptoTransform decryptor = cryptoProvider.CreateDecryptor(key, iv); Thanks, Karl

    C K 2 Replies Last reply
    0
    • K karpolu

      Greetings, I am developing an application that reads a DES encrypted password generated using Java in a properties file and decrypts it, using DESCryptoServiceProvider. I am provided with the key string originally generated with Java using DES. Does anyone have an example or sample code that converts/uses a Java generated key to decrypt a Java generated password in C#? After removing the dashes, I get the "Specified key is not a valid size for this algorithm" exception. I've tried both of these lines of code and get the same error: static byte[] key = ASCIIEncoding.ASCII.GetBytes(dashKey.Replace("-", "")); OR static byte[] key = Encoding.ASCII.GetBytes(dashKey.Replace("-", "")); The error occurrs at either of the below lines of code I tried: cryptoProvider.Key = key; OR ICryptoTransform decryptor = cryptoProvider.CreateDecryptor(key, iv); Thanks, Karl

      C Offline
      C Offline
      Calin Tatar
      wrote on last edited by
      #2

      Have you tried with different CipherModes? Are you sure you are not removing to many dashes? Calin

      1 Reply Last reply
      0
      • K karpolu

        Greetings, I am developing an application that reads a DES encrypted password generated using Java in a properties file and decrypts it, using DESCryptoServiceProvider. I am provided with the key string originally generated with Java using DES. Does anyone have an example or sample code that converts/uses a Java generated key to decrypt a Java generated password in C#? After removing the dashes, I get the "Specified key is not a valid size for this algorithm" exception. I've tried both of these lines of code and get the same error: static byte[] key = ASCIIEncoding.ASCII.GetBytes(dashKey.Replace("-", "")); OR static byte[] key = Encoding.ASCII.GetBytes(dashKey.Replace("-", "")); The error occurrs at either of the below lines of code I tried: cryptoProvider.Key = key; OR ICryptoTransform decryptor = cryptoProvider.CreateDecryptor(key, iv); Thanks, Karl

        K Offline
        K Offline
        karpolu
        wrote on last edited by
        #3

        I figured it out. The key needed to be converted into an 8 byte array.

        public static byte[] toBytes(string text)
        {
        char[] dash = { '-', '\n', '\r' };
        String[] values = text.Split(dash);
        byte[] keyArray = new byte[8];
        for (int i = 0; i < values.Length; i++)
        {
        int elem = Convert.ToInt32(values[i]);
        elem = elem & 0x00FF;
        keyArray[i] = (byte)elem;
        }
        return keyArray;
        }

        Thanx, Karl

        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