#1939 how to compute sha512 from str?

Akcelisto Fri 6 Jul 2012

I try to write something like this:

Str sha512(Str str){   
  md := MessageDigest.getInstance("SHA-512")
  md.update(str.getBytes("UTF-8"))
  byte[] byteData := md.digest
  return String.format("%1$064x", BigInteger(1, byteData)))
}

But I stuck on recieving result of String.getBytes("UTF-8") for sys::Str.

brian Fri 6 Jul 2012

fansh> "foo".toBuf.toDigest("SHA-512").toBase64                                                                                                                
9/u6bgY2+JDlb7vzKD5STG+jIErimDgtYkdB0NxmODJuKCxBvl5CVNiCB3LFUYosWowMf37aGVlKfrU5RT4e1w==

fansh> "foo".toBuf.toDigest("SHA-512").toHex                                                                                                                   
f7fbba6e0636f890e56fbbf3283e524c6fa3204ae298382d624741d0dc6638326e282c41be5e4254d8820772c5518a2c5a8c0c7f7eda19594a7eb539453e1ed7     

Login or Signup to reply.