src/com/isode/stroke/stringcodecs/PBKDF2.java
changeset 1040 197a85a35cba
parent 1039 7d6f2526244a
child 1041 e5a970600066
equal deleted inserted replaced
1039:7d6f2526244a 1040:197a85a35cba
     1 /*
       
     2  * Copyright (c) 2010, Isode Limited, London, England.
       
     3  * All rights reserved.
       
     4  */
       
     5 /*
       
     6  * Copyright (c) 2010, Remko Tronçon.
       
     7  * All rights reserved.
       
     8  */
       
     9 package com.isode.stroke.stringcodecs;
       
    10 
       
    11 import com.isode.stroke.base.ByteArray;
       
    12 
       
    13 public class PBKDF2 {
       
    14 
       
    15     public static ByteArray encode(ByteArray password, ByteArray salt, int iterations) {
       
    16         ByteArray u = HMACSHA1.getResult(password, ByteArray.plus(salt, new ByteArray("\0\0\0\1")));
       
    17         ByteArray result = new ByteArray(u);
       
    18         byte[] resultData = result.getData();
       
    19         int i = 1;
       
    20         while (i < iterations) {
       
    21             u = HMACSHA1.getResult(password, u);
       
    22             for (int j = 0; j < u.getSize(); ++j) {
       
    23                 resultData[j] ^= u.getData()[j];
       
    24             }
       
    25             ++i;
       
    26         }
       
    27         return result;
       
    28     }
       
    29 }