Guest User

Untitled

a guest
Jan 11th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. package com.bendingspoons.simpleencryption
  2.  
  3. import com.tozny.crypto.android.AesCbcWithIntegrity.*
  4. import io.flutter.plugin.common.MethodChannel
  5. import io.flutter.plugin.common.MethodChannel.MethodCallHandler
  6. import io.flutter.plugin.common.MethodChannel.Result
  7. import io.flutter.plugin.common.MethodCall
  8. import io.flutter.plugin.common.PluginRegistry.Registrar
  9.  
  10. class SimpleEncryptionPlugin() : MethodCallHandler {
  11. companion object {
  12. @JvmStatic
  13. fun registerWith(registrar: Registrar) {
  14. val channel = MethodChannel(registrar.messenger(), "simple_encryption")
  15. channel.setMethodCallHandler(SimpleEncryptionPlugin())
  16. }
  17. }
  18.  
  19. override fun onMethodCall(call: MethodCall, result: Result) {
  20. when (call.method) {
  21. "decrypt" -> {
  22. val data = call.argument<String>("data")
  23. val keyString = call.argument<String>("key")
  24.  
  25. val civ = CipherTextIvMac(data)
  26. val decrypted = decryptString(civ, keys(keyString))
  27.  
  28. result.success(decrypted)
  29. }
  30. "encrypt" -> {
  31. val data = call.argument<String>("data")
  32. val keyString = call.argument<String>("key")
  33.  
  34. val encrypted = encrypt(data, keys(keyString))
  35.  
  36. result.success(encrypted.toString())
  37. }
  38. "generate_random_key" -> {
  39. val key = generateKey()
  40. val keyString = keyString(key)
  41. result.success(keyString)
  42. }
  43. else -> result.notImplemented()
  44. }
  45. }
  46. }
Add Comment
Please, Sign In to add comment