This repository was archived by the owner on Feb 29, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Expand file tree Collapse file tree 2 files changed +44
-0
lines changed Original file line number Diff line number Diff line change 44 *
55 */
66import java .util .*;
7+
78import java .io .*;
9+ import java .security .*;
810public abstract class usacotools {
911 public static final String ANSI_RESET = "\u001B [0m" ;
1012 public static final String ANSI_BLACK = "\u001B [30m" ;
@@ -422,6 +424,26 @@ public static void LOCK() {
422424 public static void UNLOCK () {
423425 if (!(_lock )) {lock =false ;}
424426 }
427+ public static String sha256 (String input ) throws NoSuchAlgorithmException {
428+ MessageDigest md = MessageDigest .getInstance ("SHA-256" );
429+ byte [] result = md .digest (input .getBytes ());
430+ StringBuffer s = new StringBuffer ();
431+ for (int i = 0 ; i < result .length ; i ++) {
432+ s .append (Integer .toString ((result [i ] & 0xff ) + 0x100 , 16 ).substring (1 ));
433+ }
434+
435+ return s .toString ();
436+ }
437+ public static String sha (String input ,String type ) throws NoSuchAlgorithmException {
438+ MessageDigest md = MessageDigest .getInstance (type );
439+ byte [] result = md .digest (input .getBytes ());
440+ StringBuffer s = new StringBuffer ();
441+ for (int i = 0 ; i < result .length ; i ++) {
442+ s .append (Integer .toString ((result [i ] & 0xff ) + 0x100 , 16 ).substring (1 ));
443+ }
444+
445+ return s .toString ();
446+ }
425447
426448 public static void main (String [] args ) throws Exception {
427449 print ("the demo has been removed do to lack of support. Instead we display info about the library." );
Original file line number Diff line number Diff line change 44 *
55 */
66import java .util .*;
7+
78import java .io .*;
9+ import java .security .*;
810public abstract class utools {
911 public static final String ANSI_RESET = "\u001B [0m" ;
1012 public static final String ANSI_BLACK = "\u001B [30m" ;
@@ -422,6 +424,26 @@ public static void LOCK() {
422424 public static void UNLOCK () {
423425 if (!(_lock )) {lock =false ;}
424426 }
427+ public static String sha256 (String input ) throws NoSuchAlgorithmException {
428+ MessageDigest md = MessageDigest .getInstance ("SHA-256" );
429+ byte [] result = md .digest (input .getBytes ());
430+ StringBuffer s = new StringBuffer ();
431+ for (int i = 0 ; i < result .length ; i ++) {
432+ s .append (Integer .toString ((result [i ] & 0xff ) + 0x100 , 16 ).substring (1 ));
433+ }
434+
435+ return s .toString ();
436+ }
437+ public static String sha (String input ,String type ) throws NoSuchAlgorithmException {
438+ MessageDigest md = MessageDigest .getInstance (type );
439+ byte [] result = md .digest (input .getBytes ());
440+ StringBuffer s = new StringBuffer ();
441+ for (int i = 0 ; i < result .length ; i ++) {
442+ s .append (Integer .toString ((result [i ] & 0xff ) + 0x100 , 16 ).substring (1 ));
443+ }
444+
445+ return s .toString ();
446+ }
425447
426448 public static void main (String [] args ) throws Exception {
427449 print ("the demo has been removed do to lack of support. Instead we display info about the library." );
You can’t perform that action at this time.
0 commit comments