Wiki source code of webfleet_ws_key_generation
Last modified by Admin on 2019/09/10 07:01
Hide last authors
![]() |
1.1 | 1 | |
2 | To generate key you need to know account's username and password. | ||
3 | |||
4 | Using SHA-1 algorithm hash text "username;password;unixTime" and convert to hex string | ||
5 | |||
6 | Concat hex string and unixTime value with delimiter ';' in one String | ||
7 | |||
8 | Example: | ||
9 | Username = "foo" | ||
10 | Password = "bar" | ||
11 | UnixTime = 1429860412 | ||
12 | |||
13 | key = sha1Hex("foo;bar;1429860412")+";"+"1429860412" | ||
14 | |||
15 | Resulting key example: **f083777d2eaf876eca37e43e927702b4ed15d42d;1429860412** | ||
16 | |||
17 | {{code title="Key generation code in java"}} | ||
18 | |||
19 | private MessageDigest messageDigest = DigestUtils.getSha1Digest(); | ||
20 | |||
21 | public String makeKeyFor(String username, String password) { | ||
22 | DateTime now = DateTime.now(DateTimeZone.forID("UTC")); | ||
23 | int unixTime = (int) (now.getMillis() / 1000); | ||
24 | |||
25 | String unencryptedKey = String.format("%s;%s;%s", username, password, unixTime); | ||
26 | return sha1Hex(unencryptedKey) + ";" + unixTime; | ||
27 | } | ||
28 | |||
29 | private String sha1Hex(String input) { | ||
30 | return Hex.encodeHexString(messageDigest.digest(input.getBytes())); | ||
31 | } | ||
32 | {{/code}} |