PERLimport java.io.UnsupportedEncodingException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import sun.misc.BASE64Encoder; public class enc{ public static void main(String[] args){ String plaintext = "password"; MessageDigest md = null; try { md = MessageDigest.getInstance("SHA"); } catch(NoSuchAlgorithmException e) { System.exit(1); } try { //Encoding into UTF-8 System.out.print("UTF-8 : "); for(byte b : plaintext.getBytes("UTF-8")){ System.out.print(b); } System.out.println(); md.update(plaintext.getBytes("UTF-8")); } catch(UnsupportedEncodingException e) { System.exit(1); } byte raw[] = md.digest(); System.out.print("Encrypted Bytes : "); for(byte b : raw){ System.out.print(b); } System.out.println(); String hash = (new BASE64Encoder()).encode(raw); System.out.println("Encoded: " + hash); }}
name them as enc.java and enc.pl ;)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"; #$x = "jsmith"; #utf8::encode($x); # #print "0. \t\t" . $x . "\n"; #Encrypt, into bytes #@y = $sha->digest; #print "1. \t\t" . $y . "\n"; #Encode #$z = encode_base64($y); #print "2. \t\t" . $z . "\n"; #Print #print "Needs to be: \t5yfRRkrhJDbomacm2lsvEdg4GyY=";
In reply to Re^3: Convert Java to Perl -> Script attached
by smoky
in thread Convert Java to Perl -> Script attached
by smoky
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |