mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-18 12:58:24 +01:00
22 lines
867 B
Java
22 lines
867 B
Java
|
package nodomain.freeyourgadget.gadgetbridge.util;
|
||
|
|
||
|
import android.annotation.SuppressLint;
|
||
|
|
||
|
import java.security.InvalidKeyException;
|
||
|
import java.security.NoSuchAlgorithmException;
|
||
|
|
||
|
import javax.crypto.BadPaddingException;
|
||
|
import javax.crypto.Cipher;
|
||
|
import javax.crypto.IllegalBlockSizeException;
|
||
|
import javax.crypto.NoSuchPaddingException;
|
||
|
import javax.crypto.spec.SecretKeySpec;
|
||
|
|
||
|
public class CryptoUtils {
|
||
|
public static byte[] encryptAES(byte[] value, byte[] secretKey) throws InvalidKeyException, NoSuchPaddingException, NoSuchAlgorithmException, BadPaddingException, IllegalBlockSizeException {
|
||
|
@SuppressLint("GetInstance") Cipher ecipher = Cipher.getInstance("AES/ECB/NoPadding");
|
||
|
SecretKeySpec newKey = new SecretKeySpec(secretKey, "AES");
|
||
|
ecipher.init(Cipher.ENCRYPT_MODE, newKey);
|
||
|
return ecipher.doFinal(value);
|
||
|
}
|
||
|
}
|