· 8 years ago · Jun 20, 2017, 07:18 PM
1SettingsHolder.SETTINGS.setValue(RememberCredentials.class, true);
2
3 String key = TextUtils.generate(new SecureRandom().nextInt(10 - 6 + 1) + 6, TextUtils.NUMBERS);
4 System.out.println(key);
5
6 String salt = TextUtils.generate(16 - key.length(), TextUtils.LETTERS_NUMBERS_SYMBOLS);
7 System.out.println(salt);
8 SettingsHolder.SETTINGS.setValue(Salt.class, salt);
9
10 Placement place = new SecureRandom().nextInt(2) == 0 ? Placement.BEFORE : Placement.AFTER;
11 System.out.println(place.toString());
12 SettingsHolder.SETTINGS.setValue(Position.class, place);
13
14 String saltAndKey = place.equals(Placement.BEFORE) ? salt + key : key + salt;
15 System.out.println(String.format("%s:%d:%d", saltAndKey, saltAndKey.length(), saltAndKey.getBytes().length));
16
17 String keyHash = StreamHash.getStreamHash(new ByteArrayInputStream(saltAndKey.getBytes()), StreamHash.getDigest("SHA-512"));
18 SettingsHolder.SETTINGS.setValue(Hash.class, keyHash);
19 System.out.println(keyHash);
20
21 Key secretKey = new StringEncryption(saltAndKey).getKey();
22
23 String encryptedUsername = EncryptionStandard.encrypt("Daniel", secretKey);
24 SettingsHolder.SETTINGS.setValue(Username.class, encryptedUsername);
25 String encryptedPassword = EncryptionStandard.encrypt("gcnc1gekxztn", secretKey);
26 SettingsHolder.SETTINGS.setValue(Password.class, encryptedPassword);
27 System.out.println(encryptedUsername);
28
29 System.out.println(encryptedPassword);