Getting error while opening Db with encryption in Couchbase-Lite electron app

I am getting an exception while opening a database in couchbase-lite.I tried using different database name and also checked for the error and referred to this link but it seems that the error is related to the databse file format, but unable to resolve it. Here is the description for the same:

  const config = new DatabaseConfiguration();
      const database = new Database("test1", config)
      database.setEngine(new CordovaEngine({
        allResultsChunkSize: 128
      this.database = database;;

Exception message:

CouchbaseLiteException (LiteCoreDomain / 21): file/data is not in the requested format

Error Screenshot:

I have removed encryption ( config.setEncryptionKey(‘secret’)) and tried the db-open and other things,which are working seamlessly now. But nothing works if I add encryption again,how to achieve the same with encryption any idea?

I think this is the same question you asked on Stack Overflow. The flow you suggested leads me to believe you are doing the following:

  1. Opening a database without any encryption
  2. Closing that database
  3. Opening a database with encryption on the same file

It shouldn’t give the error you are reporting but that it also not a valid thing to do. Can you confirm that these are the steps you are following?

yes i am doing the same steps as mentioned by you and the question is also same asked on stack overflow, just to get more suggestion on the same I have asked it on official forum as well. Please let me know where am I doing wrong?

Well, perhaps you will understand if I say it like this:

If you’ve created a database without any encryption, why should it open correctly with an encryption key?

  1. Create an unencrypted database
  2. Close it
  3. Use an encryption key to open the same (unencrypted) database

Can you see how the above does not make sense?

If you want an encrypted database you have two choices:

  1. Create it with encryption from the beginning
  2. Open it without encryption and then use the changeEncryptionKey method to add encryption to it.

If it still does not work then I’d raise the issue with your contact on the Couchbase support team (I’m not entirely familiar with the process of this but it should have been assigned to you when you purchased the enterprise license to use encryption)

Ok, I will try this, but actually the issue was there even before encryption removal, so as per your suggestion I created a new db without encryption and it started working. But in my case will need to add the encryption. I will try once again with new db and add encryption from the start.

Still the issue persists with same error. Steps which I have followed are as follows:

1.Create a new Db with encryption
2.Store it’s instance in a object
3. call the open Db method on the same object

Point to be highlighted over here is that I am giving a new Db name or path every time whenever I am running the application And the encryption is added at the time of creating itself , following the code snippet given above with new db name always.
Can you please help me with this issue,here is the error screenshot for the same.
Error Screenshot:

Did you read the part of the error message where it says “Unsupported encryption algorithm”? What did you set the algorithm parameter to when encrypting the database?

How can you say “the same error” and then show a different error? Are you able to reproduce this in a console app without Cordova?

Attached a different screenshot sorry for the same,here is the correct one:

I am getting the same error of LiteCoreDomain/21 which is “Database exists but not in the format/storage requested”
I get the first error unsupported encryption when first time I run the app with new db name and the format error I get if I run the same app again with db name which is been used previously as well.

As per my understanding the couchbase-lite internally uses SQLCipher text AES encyption, whenever we want the db to encrypted we just need to set the configuration parameters using .setEncryptionKey() method.Correct me if I am wrong.

Couchbase no longer uses SQLCipher internally. If you want to create a database with encryption or open a database that was previously encrypted, that is the call to use to set up the configuration object.

Unsupported encryption means that a CE version of the support library is being used in conjunction with an EE version of the main library. Normally this cannot happen which is why I am asking if you can reproduce it in a console app. I want to discard any complications like Cordova (which is not something we support for .NET). The exception you get from the 2nd run is likely caused by the first one, so the first one is actually the one to work on fixing.

We are using enterprise version of support library.

The error suggests otherwise. If you can reproduce this in a normal console application then we can move forward.

Ok will try to run execute this in console app.

Unable to find the error in .net console app,so it was cordova’s issue and eventually after upgrading the version issue was solved. Thank You so much for your continuous support.:slight_smile: