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

branch
TOR_BUG_3246
changeset 4
fc2d59ddac77
equal deleted inserted replaced
-1:000000000000 0:e711bd12a724
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/. */
4
5 package org.mozilla.gecko.background.fxa;
6
7 import java.io.UnsupportedEncodingException;
8 import java.security.GeneralSecurityException;
9 import java.util.HashMap;
10 import java.util.Map;
11
12 import org.mozilla.gecko.sync.Utils;
13
14 public class QuickPasswordStretcher implements PasswordStretcher {
15 protected final String password;
16 protected final Map<String, String> cache = new HashMap<String, String>();
17
18 public QuickPasswordStretcher(String password) {
19 this.password = password;
20 }
21
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