Results 1 to 3 of 3
  1. #1
    vitaminb2's Avatar
    Join Date
    Jan 2012
    Gender
    male
    Posts
    26
    Reputation
    10
    Thanks
    3
    My Mood
    Inspired

    Need help with this source code

    Hello I got a problem with the padding after decrytion.

    (I dont want to use convert.tobase64string metheod)

    So, Ive found this source code, for encrypting and decrypting.

    For example:

    txtboxNormalString.text = "Hello"

    and pressed on encrytion button, txtboxEncrytedString.text = "??:??7s???2?),?" (Hello encrypted)

    Then pressed on Decryted button, And txtboxDecrytedString.text = "hello7s???2?),?"

    Can somebody explain me how to remove the padding after decryption.

    Encryption / decryption is new for me so i dont really know much about it for now.

    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Security.Cryptography;
    
    namespace EncryptionDecryption
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
                DesObj = Rijndael.Create();
            }
    
            string NormalString;
            byte[] CipherBytes;
            byte[] PlainBytes;
            byte[] PlainBytes2;
            byte[] PlainKey;
            SymmetricAlgorithm DesObj;
    
            private void btnEncrypt_Click(object sender, EventArgs e)
            {
                NormalString = txtboxNormalString.Text;
                PlainBytes = Encoding.ASCII.GetBytes(NormalString);
                PlainKey = Encoding.ASCII.GetBytes("12845726gh3846gs");
                DesObj.Key = PlainKey;
                DesObj.Mode = CipherMode.CBC;
                DesObj.Padding = PaddingMode.PKCS7;
                System****.MemoryStream ms = new System****.MemoryStream();
                CryptoStream cs = new CryptoStream(ms,DesObj.CreateEncryptor(), CryptoStreamMode.Write);
                cs.Write(PlainBytes, 0, PlainBytes.Length);
                cs.Close();
                CipherBytes = ms.ToArray();
                ms.Close();
                txtboxEncryptedString.Text = Encoding.ASCII.GetString(CipherBytes);
            }
    
            private void btnDecrypt_Click(object sender, EventArgs e)
            {
                System****.MemoryStream ms1 = new System****.MemoryStream(CipherBytes);
                CryptoStream cs1 = new CryptoStream(ms1, DesObj.CreateDecryptor(), CryptoStreamMode.Read);
                cs1.Read(CipherBytes, 0, CipherBytes.Length);
                PlainBytes2 = ms1.ToArray();
                cs1.Close();
                ms1.Close();
                txtboxDecryptedString.Text = Encoding.ASCII.GetString(PlainBytes2);
            }

  2. #2
    willy14's Avatar
    Join Date
    Feb 2014
    Gender
    male
    Posts
    469
    Reputation
    10
    Thanks
    82
    My Mood
    Inspired
    Might be a problem with the brackets

  3. #3
    ZER0MEM0RY's Avatar
    Join Date
    Feb 2015
    Gender
    male
    Location
    \\\\.\\PhysicalDrive0
    Posts
    94
    Reputation
    10
    Thanks
    4,218
    My Mood
    Cold
    Are you sure you're typing everything in ASCII? problem might be unicode characters, since C# project is by default in unicode.

Similar Threads

  1. [Help Request] I need help with this
    By panochito in forum DayZ Help & Requests
    Replies: 0
    Last Post: 04-28-2013, 08:49 PM
  2. [Help] Need help with a source code
    By G4M3RX in forum C++/C Programming
    Replies: 9
    Last Post: 05-05-2011, 04:33 PM
  3. Hello! i need help with the source code.
    By LatinHacker in forum Combat Arms Help
    Replies: 3
    Last Post: 05-14-2010, 10:32 PM
  4. I need help with this code in C#
    By trevor206 in forum Programming Tutorial Requests
    Replies: 0
    Last Post: 08-18-2009, 05:40 PM
  5. Need help with this error...
    By Screenlooker in forum Combat Arms Hacks & Cheats
    Replies: 6
    Last Post: 12-27-2008, 02:21 PM

Tags for this Thread