Code example for PBEParameterSpec

0
        SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
        SecretKey key = keyFactory.generateSecret(new PBEKeySpec(encryptionKey.toCharArray()));
        Cipher pbeCipher = Cipher.getInstance("PBEWithMD5AndDES");
        //TODO: 
        //pbeCipher.init(Cipher.ENCRYPT_MODE, key, new PBEParameterSpec(Settings.Secure.ANDROID_ID.getBytes(UTF8), 20)); 
        pbeCipher.init(Cipher.ENCRYPT_MODE, key, new PBEParameterSpec(Settings.Secure.ANDROID_ID.getBytes(UTF8), 20));
        return new String(Base64.encode(pbeCipher.doFinal(bytes), Base64.NO_WRAP), UTF8);
    } 
 
    /** 
     * Decrypts a string using the "PBEWithMD5AndDES" algorithm 
     * 
     * @param encryptionKey Key used to decrypt the access token 
     * @param value         String to be decrypted 
     * @return Decrypted string 
     * @throws GeneralSecurityException 
     * @throws UnsupportedEncodingException 
     */ 
    private static String decryptString(String encryptionKey, String value) throws GeneralSecurityException, UnsupportedEncodingException {
        final byte[] bytes = value != null ? Base64.decode(value, Base64.DEFAULT) : new byte[0];
        SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES");