Guest User

Untitled

a guest
Oct 22nd, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. import java.security.MessageDigest;
  2.  
  3. public class KeyStretching {
  4.  
  5. public static void main(String[] args)
  6. throws Exception {
  7.  
  8. String key = "";
  9. String password = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
  10. String salt = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
  11.  
  12. //as this is purely an example, I'm going to use sha-256
  13. //you may want to use something less 'old' in production
  14. MessageDigest md = MessageDigest.getInstance("SHA-256");
  15.  
  16. long start = System.currentTimeMillis();
  17.  
  18. byte[] byteData;
  19. StringBuilder sb = new StringBuilder(64);
  20. for (int a = 0; a < 100000; a++) {
  21. md.update((key + password + salt).getBytes());
  22. byteData = md.digest();
  23. for (int i = 0; i < byteData.length; i++) {
  24. sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
  25. }
  26. key = sb.toString();
  27. sb.delete(0, sb.length());
  28. }
  29.  
  30. float elapsed = (System.currentTimeMillis() - start) / 1000F;
  31.  
  32. System.out.println("Time : " + elapsed);
  33. System.out.println("Hex format : " + key);
  34. }
  35. }
Add Comment
Please, Sign In to add comment