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. Encryption and Decryption

Encryption and Decryption

Scheduled Pinned Locked Moved C#
helpdata-structuressecurity
2 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.
  • S Offline
    S Offline
    srinivaskonijeti
    wrote on last edited by
    #1

    HI ALL, I am using the following code for Decrtption public static string Decrypt(string xxxxx) { RijndaelManaged RijndaelCipher = new RijndaelManaged(); string Password = "srinu"; byte[] EncryptedData = Convert.FromBase64String(xxxxx); byte[] Salt = Encoding.ASCII.GetBytes(Password.Length.ToString()); //Making of the key for decryption PasswordDeriveBytes SecretKey = new PasswordDeriveBytes(Password, Salt); //Creates a symmetric Rijndael decryptor object. ICryptoTransform Decryptor = RijndaelCipher.CreateDecryptor(SecretKey.GetBytes(32), SecretKey.GetBytes(16)); MemoryStream memoryStream = new MemoryStream(EncryptedData); //Defines the cryptographics stream for decryption.THe stream contains decrpted data CryptoStream cryptoStream = new CryptoStream(memoryStream, Decryptor, CryptoStreamMode.Read); byte[] PlainText = new byte[EncryptedData.Length]; int DecryptedCount = cryptoStream.Read(PlainText, 0, PlainText.Length); memoryStream.Close(); cryptoStream.Close(); //Converting to string string DecryptedData = Encoding.Unicode.GetString(PlainText, 0, DecryptedCount); return DecryptedData; } It is showing me an error "An exception of type 'System.FormatException' occurred in .DLL but was not handled in user code Additional information: Invalid length for a Base-64 char array." in the Line "byte[] EncryptedData = Convert.FromBase64String(xxxxx);" Plz help me solve this ASAP.

    L 1 Reply Last reply
    0
    • S srinivaskonijeti

      HI ALL, I am using the following code for Decrtption public static string Decrypt(string xxxxx) { RijndaelManaged RijndaelCipher = new RijndaelManaged(); string Password = "srinu"; byte[] EncryptedData = Convert.FromBase64String(xxxxx); byte[] Salt = Encoding.ASCII.GetBytes(Password.Length.ToString()); //Making of the key for decryption PasswordDeriveBytes SecretKey = new PasswordDeriveBytes(Password, Salt); //Creates a symmetric Rijndael decryptor object. ICryptoTransform Decryptor = RijndaelCipher.CreateDecryptor(SecretKey.GetBytes(32), SecretKey.GetBytes(16)); MemoryStream memoryStream = new MemoryStream(EncryptedData); //Defines the cryptographics stream for decryption.THe stream contains decrpted data CryptoStream cryptoStream = new CryptoStream(memoryStream, Decryptor, CryptoStreamMode.Read); byte[] PlainText = new byte[EncryptedData.Length]; int DecryptedCount = cryptoStream.Read(PlainText, 0, PlainText.Length); memoryStream.Close(); cryptoStream.Close(); //Converting to string string DecryptedData = Encoding.Unicode.GetString(PlainText, 0, DecryptedCount); return DecryptedData; } It is showing me an error "An exception of type 'System.FormatException' occurred in .DLL but was not handled in user code Additional information: Invalid length for a Base-64 char array." in the Line "byte[] EncryptedData = Convert.FromBase64String(xxxxx);" Plz help me solve this ASAP.

      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      srinivaskonijeti wrote:

      Additional information: Invalid length for a Base-64 char array." in the Line "byte[] EncryptedData = Convert.FromBase64String(xxxxx);"

      It should be clear, the xxxxx string you pass in, is NOT BASE64 encoded.

      xacc.ide - now with TabsToSpaces support
      IronScheme - 1.0 alpha 4a out now (29 May 2008)
      ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))

      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