Example #1
0
        public void CreateKey()
        {
            // Removes key if it already exists, no change otherwise
            DeleteKey();
            KeyPairGenerator keyGenerator =
                KeyPairGenerator.GetInstance(KeyProperties.KeyAlgorithmRsa, KEYSTORE_NAME);

            // Parameters affiliated with the Transformation settings used when making Cipher
            var builder = new KeyGenParameterSpec.Builder(_keyAlias, KeyStorePurpose.Encrypt | KeyStorePurpose.Decrypt)
                          .SetBlockModes(KeyProperties.BlockModeEcb)
                          .SetEncryptionPaddings(KeyProperties.EncryptionPaddingRsaPkcs1)
                          .SetRandomizedEncryptionRequired(false).SetKeySize(KEY_SIZE);

            keyGenerator.Initialize(builder.Build());
            builder.Dispose();

            // Keys automattically added to KeyStore
            keyGenerator.GenerateKeyPair();
            keyGenerator.Dispose();
        }