in reply to Java to perl conversion

Have you read perlintro? Use Crypt::Twofish?

Replies are listed 'Best First'.
Re^2: Java to perl conversion
by MaGiCaLB (Initiate) on May 31, 2013 at 09:33 UTC
    The Crypt::Twofish is not the issue. the issue is to generate the exact same md5 digest. That one is build up from the bytes of the string
    java: String key = "1234567890"; perl: my $key = "1234567890";
    so I need to be able to create the exact same 256 byte array.
    java: byte[] bytes = new byte[256];
    getting the bytes of the string is also an issue
    java: byte[] kbytes = key.getBytes();
    the loop in the code is also quite simple.
    So what I really need: perl code to
    1. Generate a 256 byte array 2. perl code to convert the characters from stringdata to byte. Thanks

      Most likely, you will want to use either an array, and put the string there (split), or just use a string and substr to access the characters within the string.

      Arrays and strings are not sized in Perl.

      ... 1. Generate a 256 byte array 2. perl code to convert the characters from stringdata to byte. Thanks

      Um, you don't need to turn a string into an array to generate an md5sum, see Digest::MD5

      You also don't need an array for Crypt::Twofish

      perlintro explains about perl variable types, perldata explains further, then binmode and perlunitut

        No,

        One probably won't need to, but I have to match an API cipher
        To explain

        The encryption cipher from JAVA is out of my hands and generated by an API
        I somehow need to match the same cipher in perl

        JAVA CODE to generate the Cipher
        String key = "just a bunch of text"; byte[] bytes = new byte[256]; byte[] kbytes = key.getBytes(); for (int i = 0; i < bytes.length; i++) { if (i < kbytes.length) { bytes[i] = kbytes[i]; } else { bytes[i] = (byte) i; } } byte[] md5digest = md5DigestAsBytes(bytes); try { theGeneratedKey = Twofish_Algorithm.makeKey(md5digest); blockSize = Twofish_Algorithm.blockSize(); catch (java.security.InvalidKeyException ike) { throw new Exception(Exception.E_SECURITY, "Invalid security key ' +" + new String(md5digest) + "'", ike); }
        Question should read:
        I need to match the exact same cipher in Perl
        to be able to utilize Crypt::Twofish and decrypt the data. How can I do this in Perl

        This is my first post here.