Antom, leading provider of tailored payment solutions

Customize the security algorithm for storage API

For my.setStorage and my.getStorage storage APIs, the data will be managed in the /data/data area of the app. By default, it is stored unencrypted. To improve the security of the data, use the GriverSecurityExtension to encrypt and decrypt the data that storage APIs handle.

public interface GriverSecurityExtension extends GriverExtension {

    /**
     * Get the identifier of the algorithm, should not ne null.
     *
     * @return The identifier of the security algorithm.
     */
    String getIdentifier();

    /**
     * Encrypt given data with specific algorithm.
     *
     * @param data Data to to encrypted.
     * @return Return the encrypted data, and return null if encrypt failed.
     */
    String encrypt(String data);

    /**
     * Decrypt given data with specific algorithm.
     *
     * @param data       Data to be decrypted.
     * @param identifier The identifier of the algorithm that the encrypted data used.
     * @return Return the decrypted data, and return null if decrypt failed.
     */
    String decrypt(String data, String identifier);
}

With this extension, you can fully control the encryption and decryption of the data. So you can use custom security algorithms to improve the security.

Griver provides a default implementation by using AES algorithm. You can refer to the GriverDefaultSecurityExtension. To use the default algorithm, specify the key of AES by initWithKey method. Then register to Griver.

GriverDefaultSecurityExtension extension = new GriverDefaultSecurityExtension();
extension.initWithKey("key");
Griver.registerExtension(new GriverExtensionManifest(GriverSecurityExtension.class, extension));

Besides, you can fully implement the GriverSecurityExtension to use other algorithms. But do remember not to switch the algorithm too frequently. Each time you switch the algorithm, you must consider decrypting the legacy data encrypted by the legacy algorithm. So different algorithms should use different identifiers. The getIdentifier should return different values for different algorithms. For the default AES algorithm, Griver uses the MD5 of the privateKey which comes from initWithKey method.