java secretkey

Solutions on MaxInterview for java secretkey by the best coders in the world

showing results for - "java secretkey"
Elyes
20 Sep 2017
1// create new key
2SecretKey secretKey = KeyGenerator.getInstance("AES").generateKey();
3// get base64 encoded version of the key
4String encodedKey = Base64.getEncoder().encodeToString(secretKey.getEncoded());
5
Noelie
18 Jun 2020
1// decode the base64 encoded string
2byte[] decodedKey = Base64.getDecoder().decode(encodedKey);
3// rebuild key using SecretKeySpec
4SecretKey originalKey = new SecretKeySpec(decodedKey, 0, decodedKey.length, "AES"); 
5