smoky has asked for the wisdom of the Perl Monks concerning the following question:
I managed to get the idea of what it is doing, and how I should implement it in Perl but I just can't quite manage to get the right results.import java.io.UnsupportedEncodingException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import sun.misc.BASE64Encoder; public class x{ public static String encrypt(String plaintext){ MessageDigest md = null; try{ //Set encryption type, and set text to encrypt md = MessageDigest.getInstance("SHA"); md.update(plaintext.getBytes("UTF-8")); } catch(Exception e) { return ""; } //Encrypt bytes and return value byte raw[] = md.digest(); return (new BASE64Encoder()).encode(raw); }
Any ideas?use Digest::SHA; use utf8; no utf8; use MIME::Base64 qw(encode_base64 decode_base64); $x = "password"; utf8::encode($x); @ascii = unpack("C*", $x); print "UTF-8 : "; foreach $val (@ascii) { print $val; } print "\n"; $sha = Digest::SHA->new; $sha->add(@ascii); @z = unpack("C*",$sha->digest); print "Encrypted Bytes : "; foreach $val (@z) { print $val; } print "\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Convert Java to Perl -> Script attached
by moritz (Cardinal) on Mar 03, 2009 at 12:18 UTC | |
by smoky (Novice) on Mar 03, 2009 at 14:04 UTC | |
by smoky (Novice) on Mar 03, 2009 at 13:22 UTC | |
by almut (Canon) on Mar 03, 2009 at 14:48 UTC | |
by smoky (Novice) on Mar 03, 2009 at 13:25 UTC | |
|
Re: Convert Java to Perl -> Script attached
by roboticus (Chancellor) on Mar 03, 2009 at 11:36 UTC | |
by smoky (Novice) on Mar 03, 2009 at 12:25 UTC | |
by Anonymous Monk on Mar 03, 2009 at 12:41 UTC | |
by roboticus (Chancellor) on Mar 03, 2009 at 13:11 UTC |