Skip to content

Instantly share code, notes, and snippets.

View flschweiger's full-sized avatar

Frederik Schweiger flschweiger

View GitHub Profile
@flschweiger
flschweiger / flutter.rb
Created July 12, 2020 00:10
A Homebrew formula for the Flutter SDK
class Flutter < Formula
desc "Google’s UI toolkit for mobile, web, and desktop from a single codebase"
homepage "https://flutter.dev"
url "https://storage.googleapis.com/flutter_infra/releases/releases_macos.json"
version "sdk"
require 'json'
bottle :unneeded
@flschweiger
flschweiger / Flutter.format
Created February 16, 2019 20:19
Flutter color format file for Sip Color Picker
{
"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 October 30, 2016 10:11
A class which extends FingerprintManager.AuthenticationCallback.
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 October 29, 2016 16:44
FingerprintManager authentication.
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 October 29, 2016 11:43
Get the result from the ConfirmDeviceCredentialIntent.
@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 October 29, 2016 10:06
Fire ConfirmDeviceCredentialIntent!
private void showAuthenticationScreen() {
Intent in = mKeyguardManager.createConfirmDeviceCredentialIntent(
"Hey there!", "Please...");
if (in != null) {
startActivityForResult(in, REQUEST_CODE_CREDENTIALS);
}
}
@flschweiger
flschweiger / AesDecryptWithAuth.java
Created October 29, 2016 10:00
Decrypt super secret message with authentication.
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
@flschweiger
flschweiger / KeyGenParameterSpecBuilder.java
Created October 29, 2016 09:52
Adding authentication.
builder
.setKeySize(256)
.setBlockModes(KeyProperties.BLOCK_MODE_CBC)
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_PKCS7)
.setUserAuthenticationRequired(true)
.setUserAuthenticationValidityDurationSeconds(30);
@flschweiger
flschweiger / AesDecrypt.java
Last active October 28, 2016 21:37
Decrypt a super secret message.
// 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 October 28, 2016 21:32
Encrypt a super secret message.
// 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);