Click here to view and discuss this page in DocCommentXchange. In the future, you will be sent there automatically.

SQL Anywhere 11.0.1 (中文) » UltraLiteJ » 使用 UltraLiteJ » 开发 UltraLiteJ 应用程序

 

对数据进行加密和模糊处理

缺省情况下,存储在 UltraLiteJ 数据库中的数据不加密。可使用 API 对数据进行加密或模糊处理。加密为数据提供了非常安全的表示方式,而模糊处理是一种简化的安全保护方式,以防止随意查看数据库内容。

♦  对数据库中数据进行加密或模糊处理
  1. 创建一个实现 EncryptionControl 接口的类。

    以下示例创建一个实现加密接口的新类 Encryptor。

    static class Encryptor
        implements EncryptionControl
    {
  2. 在新类中实现 initialize、encrypt 和 decrypt 方法。

    该类应与以下所示代码类似:

    static class Encryptor
        implements EncryptionControl
    {
        /** Decrypt a page stored in the database.
         * @param page_no the number of the page being decrypted
         * @param src the encrypted source page which was read from the database
         * @param tgt the decrypted page (filled in by method)
         */
        public void decrypt( int page_no, byte[] src, byte[] tgt )
            throws ULjException
        {
            // Your decryption method goes here.
        }
        
        /** Encrypt a page stored in the database.
         * @param page_no the number of the page being encrypted
         * @param src the unencrypted source
         * @param tgt the encrypted target page which will be written to the database (filled in by method)
         */
        public void encrypt( int page_no, byte[] src, byte[] tgt )
            throws ULjException
        {
            // Your encryption method goes here.
        }
        
        /** Initialize the encryption control with a password.
         * @param password the password
         */
        public void initialize(String password)
            throws ULjException
        {
            // Your initialization method goes here.
        }
    }

    有关 EncryptionControl 方法的详细信息,请参见EncryptionControl 接口

  3. 将数据库进行配置以使用新类进行加密控制。

    可使用 setEncryption 方法指定加密控制。以下示例假定您已创建一个引用数据库名称的新 Configuration 对象 config:

    config.setEncryption(new Encryptor());
  4. 连接到数据库。

    现在,数据库中添加或修改的所有数据均已加密。

注意

加密和模糊处理对非持久性数据库存储不可用。

另请参见