BTW, here are two quick versions for running: JAVA
import 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); }}
PERL
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=";
name them as enc.java and enc.pl ;)

In reply to Re^3: Convert Java to Perl -> Script attached by smoky
in thread Convert Java to Perl -> Script attached by smoky

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.