Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package funkcjeskrotu;
- import java.io.BufferedReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.io.UnsupportedEncodingException;
- import java.math.BigInteger;
- import java.security.MessageDigest;
- import java.security.NoSuchAlgorithmException;
- import javax.xml.bind.DatatypeConverter;
- import static javax.xml.bind.DatatypeConverter.printHexBinary;
- /**
- *
- * @author tpodkowski
- */
- public class FunkcjeSkrotu {
- /**
- * @param args the command line arguments
- */
- public static String getTextFromUser() {
- BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
- String text = "";
- try {
- text = buffer.readLine();
- } catch (IOException e) {
- }
- return text;
- }
- public static String toHash(String method, String text) {
- try {
- long startTime = System.nanoTime();
- MessageDigest m = MessageDigest.getInstance(method);
- m.reset();
- m.update(text.getBytes());
- byte[] digest = m.digest();
- BigInteger bigInt = new BigInteger(1, digest);
- System.out.println(method + " time: " + (System.nanoTime() - startTime));
- return bigInt.toString(16);
- } catch (NoSuchAlgorithmException e) {
- return "";
- }
- }
- public static void main(String[] args) {
- String text = getTextFromUser();
- System.out.println("MD5: " + toHash("MD5", text));
- System.out.println("SHA-1: " + toHash("SHA-1", text));
- System.out.println("SHA-256: " + toHash("SHA-256", text));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement