Code example for SecretKey

Methods: getEncoded

0
     * @return A randomly generated key, encoded as a Base64 String. 
     * @throws NoSuchAlgorithmException if the AES algorithm is unavailable. 
     */ 
    public String genRandomBase64KeyString() throws NoSuchAlgorithmException {
        SecretKey key = genRandomKey();
        byte[] keyBytes = key.getEncoded();
        String b64String = new String(Base64.encode(keyBytes, Base64.DEFAULT));
        return b64String;
    } 
 
    /** 
     * @param password The password to generate the key from. 
     * @param salt Some bytes to salt the password with. 
     * @param iterations How many iterations to use when generating the key. 
     * @return A key produced from the given password and parameters. 
     * @throws NoSuchAlgorithmException if the PBKDF2 algorithm was unavailable. 
     * @throws InvalidKeySpecException if the keyspec produced from the given parameters is 
     * rejected. 
     */ 
    public SecretKey genKeyPwkdf2(String password, byte[] salt, int iterations)
            throws NoSuchAlgorithmException, InvalidKeySpecException {