Thread Entschlüsselung
(2 answers)
Opened by MarkusH at 2016-04-02 18:11
Hallo zusammen,
ich beschäftige mich schon seit dem frühen Vormittag damit, die folgende C#-Methode in Perl umzusetzen. Code: (dl
)
1 private static byte[] Decode(byte[] cipherData, byte[] key, byte[] initVector) Dazu habe ich nun folgenden Code gezimmert. Code (perl): (dl
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 #!/usr/bin/perl -w use strict; use Crypt::Rijndael; use Crypt::CBC; use Convert::Base64; my $encodedString = 'AI8Xv81IsklU/SLZDV8sW4EqUWKh4yiOm/y0WE5PPmXrciz1NyP3zDzirY1vq0/2wPD0m8ZlTHeGL4Cpygs7/CJAS9pyEz47/Apnn5qix45YpH7m2OXxug/04UyuOFnH'; my @keyArray = (231, 216, 3, 26, 247, 91, 73, 223, 222, 174, 20, 122, 30, 27, 240, 211, 219, 51, 217, 212, 22, 94, 219, 239, 147, 12, 164, 230, 73, 168, 72, 247); my @ivArray = (222, 174, 20, 122, 30, 27, 240, 211, 95, 191, 236, 203, 64, 122, 254, 71); my $key = CreateString(@keyArray); my $initVector = CreateString(@ivArray); my $decryptedString = Encode::decode("UTF-16LE",Decrypt($encodedString, $key, $initVector)); print $decryptedString; sub Decrypt { my $encodedString = shift; my $key = shift; my $initVector = shift; #1. Schritt #Das Array mit den korrekten Daten #my @cipherData =(0, 143, 23, 191, 205, 72, 178, 73, 84, 253, 34, 217, 13, 95, 44, 91, 129, 42, 81, 98, 161, 227, 40, 142, 155, 252, 180, 88, 78, 79, 62, 101, 235, 114, 44, 245, 55, 35, 247, 204, 60, 226, 173, 141, 111, 171, 79, 246, 192, 240, 244, 155, 198, 101, 76, 119, 134, 47, 128, 169, 202, 11, 59, 252, 34, 64, 75, 218, 114, 19, 62, 59, 252, 10, 103, 159, 154, 162, 199, 142, 88, 164, 126, 230, 216, 229, 241, 186, 15, 244, 225, 76, 174, 56, 89, 199); my @cipherData = DecodeBase64ToArray($encodedString); #2. Schritt my @decryptedData = (); #Das Array mit den korrekten Daten #@decryptedData = (80, 0, 101, 0, 114, 0, 108, 0, 32, 0, 117, 0, 110, 0, 100, 0, 32, 0, 67, 0, 35, 0, 32, 0, 115, 0, 105, 0, 110, 0, 100, 0, 32, 0, 99, 0, 111, 0, 111, 0, 108, 0, 101, 0, 32, 0, 80, 0, 114, 0, 111, 0, 103, 0, 114, 0, 97, 0, 109, 0, 109, 0, 105, 0, 101, 0, 114, 0, 115, 0, 112, 0, 114, 0, 97, 0, 99, 0, 104, 0, 101, 0, 110, 0, 33, 0); #Hier mit string als Test my $base64String = DecodeBase64ToString($encodedString); my $cipher = Crypt::CBC->new( { key => $key, #The encryption/decryption key (required) cipher => 'Rijndael', #The cipher algorithm (defaults to Crypt::DES), or a preexisting cipher object. iv => $initVector, #The initialization vector (IV) header => 'none', #What type of header to prepend to ciphertext. One of 'salt' -- use OpenSSL-compatible salted header 'randomiv' -- Randomiv-compatible "RandomIV" header 'none' -- prepend no header at all padding => 'standard', #The padding method, one of "standard" (default), "space", "oneandzeroes", "rijndael_compat", "null", or "none" (default "standard"). literal_key => 0, #If true, the key provided by "key" is used directly for encryption/decryption. Otherwise the actual key used will be a hash of the provided key. (default false) pcbc => 0, #Whether to use the PCBC chaining algorithm rather than the standard CBC algorithm (default false) keysize => 32, #Force the cipher keysize to the indicated number of bytes. blocksize => 16 #Force the cipher blocksize to the indicated number of bytes. } ); foreach my $value (@cipherData) { push(@decryptedData, $cipher->decrypt($value)); } #Hier mit string als Test my $decodedString = $cipher->decrypt($base64String); #3. Schritt my $unicodeString = ConvertToUnicode(@decryptedData); return $unicodeString; } sub ConvertToUnicode { my @byteArray = @_; return join('', map chr, @byteArray); } sub DecodeBase64ToArray { my $encodedString = shift; my @base64decoded = (); my $base64string = unpack("H*",decode_base64($encodedString)); my @base64HexDecoded = $base64string =~ /\w{2}/g; @base64decoded = ConvertToDecimal(@base64HexDecoded); return @base64decoded; } sub DecodeBase64ToString { my $encodedString = shift; return decode_base64($encodedString); } sub ConvertToDecimal { my @hexArray = @_; my @returnArray = (); foreach my $hexValue (@hexArray) { push(@returnArray, hex($hexValue)); } return @returnArray; } sub CreateString { my @array = @_; my @chars = (); foreach my $value (@array) { push(@chars, chr($value)); } return join('', @chars); } Der zweite Schritt im Perl-Code soll der C#-Methode entsprechen. Die Arrays mit den richtigen Daten habe ich auskommentiert. Ich schaffe es aber nicht, das Array mit den korrekten Daten (@decryptedData) zu erstellen. Ist die dabei verwendete Methode ($cipher = Crypt::CBC->new) überhaupt richtig? Bitte um Hilfestellung! $q =~ /(bb|[^b]{2})/
|