Code example for SecretKey

Methods: getEncoded

0
 
            try { 
                SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
                KeySpec keySpec = new PBEKeySpec(passwordChars, saltBytes, 1024, 256);
                SecretKey secretKey = keyFactory.generateSecret(keySpec);
                return secretKey.getEncoded();
            } catch (NoSuchAlgorithmException e) {
                Log.e(TAG, "NoSuchAlgorithmException", e);
                throw new AssertionError(e);
            } catch (InvalidKeySpecException e) {
                Log.e(TAG, "InvalidKeySpecException", e);
                throw new AssertionError(e);
            } 
        } 
 
        public static String getDerivedKeyBase64(String password, String salt) {
            return Base64.encodeToString(getDerivedKey(password, salt), Base64.NO_WRAP);
        } 
    } 
 
    public static class HMAC {