mobile/android/base/background/fxa/QuickPasswordStretcher.java

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 package org.mozilla.gecko.background.fxa;
     7 import java.io.UnsupportedEncodingException;
     8 import java.security.GeneralSecurityException;
     9 import java.util.HashMap;
    10 import java.util.Map;
    12 import org.mozilla.gecko.sync.Utils;
    14 public class QuickPasswordStretcher implements PasswordStretcher {
    15   protected final String password;
    16   protected final Map<String, String> cache = new HashMap<String, String>();
    18   public QuickPasswordStretcher(String password) {
    19     this.password = password;
    20   }
    22   public synchronized byte[] getQuickStretchedPW(byte[] emailUTF8) throws UnsupportedEncodingException, GeneralSecurityException {
    23     if (emailUTF8 == null) {
    24       throw new IllegalArgumentException("emailUTF8 must not be null");
    25     }
    26     String key = Utils.byte2Hex(emailUTF8);
    27     if (!cache.containsKey(key)) {
    28       byte[] value = FxAccountUtils.generateQuickStretchedPW(emailUTF8, password.getBytes("UTF-8"));
    29       cache.put(key, Utils.byte2Hex(value));
    30       return value;
    31     }
    32     return Utils.hex2Byte(cache.get(key));
    33   }
    34 }

mercurial