     }
     
     public func initPGPKey(_ keyType: PgpKey) throws {
+        // Clean up the previously set public/private key.
+        switch keyType {
+        case .PUBLIC:
+            self.publicKey = nil
+            self.publicKeyV2 = nil
+        case .PRIVATE:
+            self.privateKey = nil
+            self.privateKeyV2 = nil
+        }
+        
         // Read the key data from keychain.
         guard let pgpKeyData: Data = AppKeychain.get(for: keyType.getKeychainKey()) else {
             throw AppError.KeyImport

        
        // Try GopenpgpwrapperReadKey first.
        if let key = GopenpgpwrapperReadKey(pgpKeyData) {
            switch keyType {
            case .PUBLIC:
                self.publicKey = key

        // [ObjectivePGP.readKeys MAY CRASH!!!]
        if let keys = try? ObjectivePGP.readKeys(from: pgpKeyData),
            let key = keys.first {
            print("ObjectivePGP \(keyType)")
            keyring.import(keys: keys)
            switch keyType {
            case .PUBLIC:
