Help Center> Object Storage Service> Android> Initialization> Transparently Transferring the AK and SK
Updated on 2023-11-09 GMT+08:00

Transparently Transferring the AK and SK

If you have any questions during development, post them on the Issues page of GitHub. For details about parameters and usage of each API, see the API Reference

OBS Android SDK provides SecretFlexibleObsClient that support transparent transfer of AKs and SKs in API functions. Sample code is as follows:

String endPoint = "https://your-endpoint";
// Create an instance of ObsConfiguration.
ObsConfiguration config = new ObsConfiguration();
config.setEndPoint(endPoint);

// Create an instance of SecretFlexibleObsClient.
SecretFlexibleObsClient obsClient = new SecretFlexibleObsClient(config);
// Use the instance to access OBS.
// Hard-coded or plaintext AK/SK are risky. For security purposes, encrypt your AK/SK and store them in the configuration file or environment variables. In this example, the AK/SK are stored in environment variables for identity authentication. Before running this example, configure environment variables ACCESS_KEY_ID and SECRET_ACCESS_KEY_ID.
// Obtain an AK/SK pair on the management console. For details, see https://support.huaweicloud.com/intl/en-us/usermanual-ca/ca_01_0003.html.
String ak1 = System.getenv("ACCESS_KEY_ID1");
String sk1 = System.getenv("SECRET_ACCESS_KEY_ID1");
obsClient.listBuckets(ak1, sk1);

String ak2 = System.getenv("ACCESS_KEY_ID2");
String sk2 = System.getenv("SECRET_ACCESS_KEY_ID2");
obsClient.listBuckets(ak2, sk2);

// Close obsClient.
obsClient.close();

SecretFlexibleObsClient is inherited from ObsClient and can be used as ObsClient.