michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: package org.mozilla.gecko.background.fxa; michael@0: michael@0: import java.io.UnsupportedEncodingException; michael@0: import java.security.GeneralSecurityException; michael@0: import java.util.HashMap; michael@0: import java.util.Map; michael@0: michael@0: import org.mozilla.gecko.sync.Utils; michael@0: michael@0: public class QuickPasswordStretcher implements PasswordStretcher { michael@0: protected final String password; michael@0: protected final Map cache = new HashMap(); michael@0: michael@0: public QuickPasswordStretcher(String password) { michael@0: this.password = password; michael@0: } michael@0: michael@0: public synchronized byte[] getQuickStretchedPW(byte[] emailUTF8) throws UnsupportedEncodingException, GeneralSecurityException { michael@0: if (emailUTF8 == null) { michael@0: throw new IllegalArgumentException("emailUTF8 must not be null"); michael@0: } michael@0: String key = Utils.byte2Hex(emailUTF8); michael@0: if (!cache.containsKey(key)) { michael@0: byte[] value = FxAccountUtils.generateQuickStretchedPW(emailUTF8, password.getBytes("UTF-8")); michael@0: cache.put(key, Utils.byte2Hex(value)); michael@0: return value; michael@0: } michael@0: return Utils.hex2Byte(cache.get(key)); michael@0: } michael@0: }