Asymmetric Key Generation in Flutter

Gonçalo Palma
Flutter Community
Published in
7 min readMar 10, 2019

--

Photo by Giulio Magnifico on Unsplash

When developing applications focused on security and encryption, we may need to use Asymmetric Keys in order to sign and verify data before sending it to our servers. Though the encryption algorithms may be complex, we can use the help of libraries such as Pointy Castle to integrate it in our Flutter applications.

PointyCastle is a port of Java’s Bouncy Castle and it provides us the implementation for the most commonly used cryptography algorithms. With this library we will create the main methods to build an app example, that is able to generate a new asymmetric key pair and sign a message with a private key.

RSA Key Generation Example App

In order to achieve this result, we will have to go through the following steps:

  1. Generating a RSA KeyPair using PointyCastle’s RSAKeyGenerator
  2. Using Isolate for optimizing the generation of a KeyPair
  3. Encoding Asymmetric Keys to Plain Text
  4. Signing a message with a Private Key

We will also look into the curious case of generating keys in a physical iOS device in Debug Mode.

Generating a RSA KeyPair using…

--

--

Gonçalo Palma
Flutter Community

Author, Flutter Lead Developer @Pvotal Tech. Organizer, Google Developer Expert for Flutter and Dart, Lead Flutter Developer. 🌍 https://gpalma.pt/