This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Very helpful comment. | |
*/ | |
typealias KotlinFunctionAlias = (Item) -> String | |
fun delegateAliasWork(f: KotlinFunctionAlias): String { | |
return f.invoke(item) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface KotlinInterface { | |
fun doSomething(item: Item): String | |
} | |
class KotlinComponent(private val item: Item = Item()) { | |
fun delegateWork(f: KotlinInterface): String { | |
return f.doSomething(item) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@FunctionalInterface | |
interface JavaInterface { | |
String doSomething(Item item); | |
} | |
class JavaComponent { | |
private Item item = new Item(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@FunctionalInterface | |
interface JavaInterface { | |
String doSomething(Item item); | |
} | |
String delegateWork(JavaInterface f) { | |
return f.doSomething(item); | |
} | |
String delegateOtherWork(Function<Item, String> f) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface JavaInterface { | |
String doSomething(Item item); | |
} | |
String delegateWork(JavaInterface f) { | |
return f.doSomething(item); | |
} | |
void doWork() { | |
delegateWork(new JavaInterface() { |