Skip to content

Instantly share code, notes, and snippets.

View stravag's full-sized avatar

Ranil Wijeyratne stravag

View GitHub Profile
fun getKey(): Key? {
val keyStore: KeyStore = KeyStore.getInstance("AndroidKeyStore").apply {
load(null)
}
return keyStore.getKey("MY_KEY", null)
}
fun getDecryptCipher(key: Key, iv: ByteArray): Cipher {
val algorithm = KeyProperties.KEY_ALGORITHM_AES
val blockMode = KeyProperties.BLOCK_MODE_CBC
fun createKey(): SecretKey {
val algorithm = KeyProperties.KEY_ALGORITHM_AES
val provider = "AndroidKeyStore"
val keyGenerator = KeyGenerator.getInstance(algorithm, provider)
val keyName = "MY_KEY"
val purposes = KeyProperties.PURPOSE_ENCRYPT or KeyProperties.PURPOSE_DECRYPT
val keyGenParameterSpec = KeyGenParameterSpec.Builder(keyName, purposes)
.setBlockModes(BLOCK_MODE)
.setEncryptionPaddings(PADDING)
/**
* Very helpful comment.
*/
typealias KotlinFunctionAlias = (Item) -> String
fun delegateAliasWork(f: KotlinFunctionAlias): String {
return f.invoke(item)
}
interface KotlinInterface {
fun doSomething(item: Item): String
}
class KotlinComponent(private val item: Item = Item()) {
fun delegateWork(f: KotlinInterface): String {
return f.doSomething(item)
}
class KotlinComponent(private val item: Item = Item()) {
fun delegateWork(f: JavaInterface): String {
return f.doSomething(item)
}
fun delegateOtherWork(f: (Item) -> String): String {
return f.invoke(item)
}
}
@FunctionalInterface
interface JavaInterface {
String doSomething(Item item);
}
class JavaComponent {
private Item item = new Item();
@FunctionalInterface
interface JavaInterface {
String doSomething(Item item);
}
String delegateWork(JavaInterface f) {
return f.doSomething(item);
}
String delegateOtherWork(Function<Item, String> f) {
interface JavaInterface {
String doSomething(Item item);
}
String delegateWork(JavaInterface f) {
return f.doSomething(item);
}
void doWork() {
delegateWork(new JavaInterface() {