Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.security.MessageDigest;
- public class KeyStretching {
- public static void main(String[] args)
- throws Exception {
- String key = "";
- String password = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
- String salt = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
- //as this is purely an example, I'm going to use sha-256
- //you may want to use something less 'old' in production
- MessageDigest md = MessageDigest.getInstance("SHA-256");
- long start = System.currentTimeMillis();
- byte[] byteData;
- StringBuilder sb = new StringBuilder(64);
- for (int a = 0; a < 100000; a++) {
- md.update((key + password + salt).getBytes());
- byteData = md.digest();
- for (int i = 0; i < byteData.length; i++) {
- sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
- }
- key = sb.toString();
- sb.delete(0, sb.length());
- }
- float elapsed = (System.currentTimeMillis() - start) / 1000F;
- System.out.println("Time : " + elapsed);
- System.out.println("Hex format : " + key);
- }
- }
Add Comment
Please, Sign In to add comment