Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.bendingspoons.simpleencryption
- import com.tozny.crypto.android.AesCbcWithIntegrity.*
- import io.flutter.plugin.common.MethodChannel
- import io.flutter.plugin.common.MethodChannel.MethodCallHandler
- import io.flutter.plugin.common.MethodChannel.Result
- import io.flutter.plugin.common.MethodCall
- import io.flutter.plugin.common.PluginRegistry.Registrar
- class SimpleEncryptionPlugin() : MethodCallHandler {
- companion object {
- @JvmStatic
- fun registerWith(registrar: Registrar) {
- val channel = MethodChannel(registrar.messenger(), "simple_encryption")
- channel.setMethodCallHandler(SimpleEncryptionPlugin())
- }
- }
- override fun onMethodCall(call: MethodCall, result: Result) {
- when (call.method) {
- "decrypt" -> {
- val data = call.argument<String>("data")
- val keyString = call.argument<String>("key")
- val civ = CipherTextIvMac(data)
- val decrypted = decryptString(civ, keys(keyString))
- result.success(decrypted)
- }
- "encrypt" -> {
- val data = call.argument<String>("data")
- val keyString = call.argument<String>("key")
- val encrypted = encrypt(data, keys(keyString))
- result.success(encrypted.toString())
- }
- "generate_random_key" -> {
- val key = generateKey()
- val keyString = keyString(key)
- result.success(keyString)
- }
- else -> result.notImplemented()
- }
- }
- }
Add Comment
Please, Sign In to add comment