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. C# Rijndael Encrypt and Pel Crypt::CBC

C# Rijndael Encrypt and Pel Crypt::CBC

Scheduled Pinned Locked Moved C#
perlcsharpsecuritytoolshelp
1 Posts 1 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.
  • D Offline
    D Offline
    DanielLC
    wrote on last edited by
    #1

    Hi, I'm trying to encrypt a string in c# that would be decrypted with perl. The problem is that in the perl script there is not IV specified so, when I encrypt the result is not readable be the perl decryptor. Is there any workaround to know who perl auto generate the IV (I suppose that's what it does) ?

    C# Code to Encrypt :

        private string strCryptoMessage(string strOrig, string strKey)
        {
            System.Security.Cryptography.RijndaelManaged rj = new System.Security.Cryptography.RijndaelManaged();
            rj.Mode = System.Security.Cryptography.CipherMode.CBC;
            rj.Key = Encoding.UTF8.GetBytes(strKey);
    
            byte\[\] bOrig = Encoding.UTF8.GetBytes(strOrig);
    
            System.IO.MemoryStream ms = new System.IO.MemoryStream();
    
            System.Security.Cryptography.CryptoStream cs = new System.Security.Cryptography.CryptoStream(ms, rj.CreateEncryptor(), System.Security.Cryptography.CryptoStreamMode.Write);
    
            cs.Write(bOrig, 0, bOrig.Length);
            cs.FlushFinalBlock();
    
            string bResult = Convert.ToBase64String(ms.ToArray());
            ms.Flush();
    
            
            return bResult;
        }
    

    Perl Code To Encrypt :

    #!/opt/local/bin/perl -w

    use IO::Socket;
    use IO::Handle;
    use MIME::Base64;
    use Data::Dumper;
    use POSIX;
    use Getopt::Long;
    use strict;

    require Crypt::CBC;

    my $msg = "MESSAGE_TO_ENCRYPT";
    my $enc_key = "SAME_AS_strKey";
    my $enc_alg = "Rijndael";

    my $cipher = Crypt::CBC->new({
    'key' => $enc_key,
    'cipher' => $enc_alg,
    });

    my $encrypted\_msg = $cipher->encrypt($msg);
    print "$msg\\n";
    
    my $encoded\_msg = encode\_base64($encrypted\_msg, '');
    print "$encoded\_msg\\n";
    

    Both should generate the same result, but I think that the perl Crypt::CBC generate the IV code using the key in some way.

    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