app/src/main/java/com/isode/stroke/stringcodecs/PBKDF2.java
author Da Risk <da_risk@beem-project.com>
Sun, 15 Mar 2015 18:03:03 +0100
changeset 1044 197a85a35cba
parent 1018 src/com/isode/stroke/stringcodecs/PBKDF2.java@8daca77fabc1
permissions -rw-r--r--
Move the app into an app submodule which respect the default gradle layout

/*
 * Copyright (c) 2010, Isode Limited, London, England.
 * All rights reserved.
 */
/*
 * Copyright (c) 2010, Remko Tronçon.
 * All rights reserved.
 */
package com.isode.stroke.stringcodecs;

import com.isode.stroke.base.ByteArray;

public class PBKDF2 {

    public static ByteArray encode(ByteArray password, ByteArray salt, int iterations) {
        ByteArray u = HMACSHA1.getResult(password, ByteArray.plus(salt, new ByteArray("\0\0\0\1")));
        ByteArray result = new ByteArray(u);
        byte[] resultData = result.getData();
        int i = 1;
        while (i < iterations) {
            u = HMACSHA1.getResult(password, u);
            for (int j = 0; j < u.getSize(); ++j) {
                resultData[j] ^= u.getData()[j];
            }
            ++i;
        }
        return result;
    }
}