public class

SQLiteCipherSpec

extends Object
java.lang.Object
   ↳ com.tencent.wcdb.database.SQLiteCipherSpec

Class Overview

Describes encryption options for SQLite databases.

Summary

Constants
String CIPHER_AES256CBC 256-bit AES encryption, CBC mode.
Fields
public String cipher Encryption method used, null for default method, which is 256-bit AES in CBC mode.
public boolean hmacEnabled Whether HMAC should be used.
public int kdfIteration KDF iteration times to generate encryption keys, 0 for default value.
public int pageSize Page size to use.
Public Constructors
SQLiteCipherSpec()
Create a new object with default values.
SQLiteCipherSpec(SQLiteCipherSpec rhs)
Create a new object as a copy of an existed one.
Public Methods
SQLiteCipherSpec setCipher(String c)
Set encryption method to be used.
SQLiteCipherSpec setKDFIteration(int iter)
Set KDF iteration times to be used.
SQLiteCipherSpec setPageSize(int size)
Set the page size to use.
SQLiteCipherSpec setSQLCipherVersion(int version)
Set SQLCipher version compatibility.
SQLiteCipherSpec withHMACEnabled(boolean enabled)
Set whether to use HMAC in encryption.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final String CIPHER_AES256CBC

256-bit AES encryption, CBC mode.

Constant Value: "aes-256-cbc"

Fields

public String cipher

Encryption method used, null for default method, which is 256-bit AES in CBC mode.

public boolean hmacEnabled

Whether HMAC should be used.

Defaulted to false for SQLCipher 1.x, and true otherwise. Must be set to the same value as when the database is created, or the database cannot be opened and SQLiteException is thrown.

public int kdfIteration

KDF iteration times to generate encryption keys, 0 for default value.

Typical values are 4000 for SQLCipher version 1.x and 2.x, 64000 for version 3.x. For databases created by WCDB itself, leave it 0.

public int pageSize

Page size to use.

Page size must be set to the same value as when the database is created, in order to open existing encrypted database. For databases created by WCDB itself, leave it to the default is preferred for most applications. If database cannot be opened and SQLiteException is thrown, try setting it to 1024 or 4096.

Public Constructors

public SQLiteCipherSpec ()

Create a new object with default values.

public SQLiteCipherSpec (SQLiteCipherSpec rhs)

Create a new object as a copy of an existed one.

Parameters
rhs The object to be copied

Public Methods

public SQLiteCipherSpec setCipher (String c)

Set encryption method to be used.

Parameters
c The method name to be used
Returns
  • This object to allow for chaining of calls to set methods
See Also

public SQLiteCipherSpec setKDFIteration (int iter)

Set KDF iteration times to be used.

Parameters
iter New iteration times value
Returns
  • This object to allow for chaining of calls to set methods
See Also

public SQLiteCipherSpec setPageSize (int size)

Set the page size to use. The page size should be a power of two.

Parameters
size Page size in byte
Returns
  • This object to allow for chaining of calls to set methods
See Also

public SQLiteCipherSpec setSQLCipherVersion (int version)

Set SQLCipher version compatibility. The version should be 1, 2 or 3 which represent SQLCipher 1.x, 2.x or 3.x. This method overwrites HMAC and KDF iteration settings.

Parameters
version SQLCipher version, should be 1, 2 or 3
Returns
  • This object to allow for chaining of calls to set methods

public SQLiteCipherSpec withHMACEnabled (boolean enabled)

Set whether to use HMAC in encryption. Default to true.

Parameters
enabled Whether to use HMAC
Returns
  • This object to allow for chaining of calls to set methods
See Also