Skip to content

Instantly share code, notes, and snippets.

Frederik Schweiger flschweiger

Block or report user

Report or block flschweiger

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@flschweiger
flschweiger / Flutter.format
Created Feb 16, 2019
Flutter color format file for Sip Color Picker
View Flutter.format
{
"name" : "Flutter",
"clipboardFormat" : {
"function" : "concat",
"y" : ")",
"x" : {
"x" : "const Color(0xFF",
"function" : "concat",
"y" : {
"x" : "hex[red]hex[green]hex[blue]",
@flschweiger
flschweiger / AuthCallbacks.java
Last active Oct 30, 2016
A class which extends FingerprintManager.AuthenticationCallback.
View AuthCallbacks.java
class AuthCallbacks extends FingerprintManager.AuthenticationCallback {
@Override
public void onAuthenticationSucceeded(FingerprintManager.AuthenticationResult result) {
// Called when a fingerprint is recognized.
// The AuthenticationResult contains the CryptoObject which
// has been passed to the authenticate() method.
Cipher cipher = result.getCryptoObject().getCipher();
// Go on and use the 'unlocked' Cipher object...
@flschweiger
flschweiger / FingerprintDialog.java
Last active Oct 29, 2016
FingerprintManager authentication.
View FingerprintDialog.java
fingerprintManager = (FingerprintManager)
getSystemService(Context.FINGERPRINT_SERVICE);
fingerprintManager.authenticate(
@Nullable FingerprintManager.CryptoObject cryptoObject,
@Nullable CancellationSignal cancelSignal,
0 /* optional flags - should be 0 */,
FingerprintManager.AuthenticationCallback callback,
@Nullable Handler handler);
@flschweiger
flschweiger / MainActivity.java
Created Oct 29, 2016
Get the result from the ConfirmDeviceCredentialIntent.
View MainActivity.java
@Override
protected void onActivityResult(int requestCode,
int resultCode, Intent data) {
if (requestCode == REQUEST_CODE_CREDENTIALS) {
// Challenge completed, proceed with using cipher
if (resultCode == RESULT_OK) {
doSomeDecryptionHere();
} else {
// The user canceled or didn’t complete the lock screen
// operation. Go to error/cancellation flow.
@flschweiger
flschweiger / MainActivity.java
Created Oct 29, 2016
Fire ConfirmDeviceCredentialIntent!
View MainActivity.java
private void showAuthenticationScreen() {
Intent in = mKeyguardManager.createConfirmDeviceCredentialIntent(
"Hey there!", "Please...");
if (in != null) {
startActivityForResult(in, REQUEST_CODE_CREDENTIALS);
}
}
@flschweiger
flschweiger / AesDecryptWithAuth.java
Created Oct 29, 2016
Decrypt super secret message with authentication.
View AesDecryptWithAuth.java
try {
KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore");
keyStore.load(null);
SecretKey secretKey =
(SecretKey) keyStore.getKey(SecurityConstants.KEY_AES, null);
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS7Padding");
// The next line may throw a UserNotAuthenticatedException and
// we need to prompt the user to authenticate again
View KeyGenParameterSpecBuilder.java
builder
.setKeySize(256)
.setBlockModes(KeyProperties.BLOCK_MODE_CBC)
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_PKCS7)
.setUserAuthenticationRequired(true)
.setUserAuthenticationValidityDurationSeconds(30);
@flschweiger
flschweiger / AesDecrypt.java
Last active Oct 28, 2016
Decrypt a super secret message.
View AesDecrypt.java
// Init the Cipher and decrypt the ciphertext
cipher.init(Cipher.DECRYPT_MODE, secretKey, new IvParameterSpec(iv));
byte[] decryptedBytes =
cipher.doFinal(encryptedBytes);
@flschweiger
flschweiger / AesEncrypt.java
Created Oct 28, 2016
Encrypt a super secret message.
View AesEncrypt.java
// Get the AndroidKeyStore instance
KeyStore keyStore = KeyStore.getInstance("AndroidKeyStore");
// Relict of the JCA API - you have to call load even
// if you do not have an input stream you want to load or it'll crash
keyStore.load(null);
// Get the SecretKey from the KeyStore and instantiate a Cipher
SecretKey secretKey =
(SecretKey) keyStore.getKey("myAwesomeSecretKey01", null);
@flschweiger
flschweiger / AesKeyGenerator.java
Last active Mar 2, 2020
Create a symmetric key inside the Android Keystore.
View AesKeyGenerator.java
// Get the KeyGenerator instance for AES
KeyGenerator keyGenerator = KeyGenerator.getInstance(
KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore");
// Create a KeyGenParameterSpec builder and
// set the alias and different purposes of the key
KeyGenParameterSpec.Builder builder = new KeyGenParameterSpec.Builder(
"myAwesomeSecretKey01",
KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT);
You can’t perform that action at this time.