mirror of
https://github.com/oxen-io/session-android.git
synced 2025-12-11 22:01:52 +00:00
both org.thoughtcrime.redphone.util and org.thoughtcrime.securesms.util have a Base64 util class, however, other than whitespace changes, and the securesms one having a couple of extra methods, they are the same. This commit removes org.thoughtcrime.redphone.util.Base64 and anything referencing it now uses org.thoughtcrime.securesms.util.Base64 Closes #4294
48 lines
1.5 KiB
Java
48 lines
1.5 KiB
Java
/*
|
|
* Copyright (C) 2011 Whisper Systems
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
package org.thoughtcrime.redphone.crypto;
|
|
|
|
import org.thoughtcrime.securesms.util.Base64;
|
|
|
|
import java.security.InvalidKeyException;
|
|
import java.security.NoSuchAlgorithmException;
|
|
|
|
import javax.crypto.Mac;
|
|
import javax.crypto.spec.SecretKeySpec;
|
|
|
|
/**
|
|
* A utility class for calcuating a HOTP token from a user's
|
|
* password and the current counter value.
|
|
*
|
|
* @author Moxie Marlinspike
|
|
*
|
|
*/
|
|
public class Otp {
|
|
public static String calculateOtp(String password, long counter) {
|
|
try {
|
|
SecretKeySpec key = new SecretKeySpec(password.getBytes(), "HmacSHA1");
|
|
Mac mac = Mac.getInstance("HmacSHA1");
|
|
mac.init(key);
|
|
|
|
return Base64.encodeBytes(mac.doFinal((counter+"").getBytes()));
|
|
} catch (NoSuchAlgorithmException | InvalidKeyException nsae) {
|
|
throw new AssertionError(nsae);
|
|
}
|
|
}
|
|
}
|