# Encryption and Decryption source: https://developer.mastercard.com/priceless-planet-carbon-tracker/tutorial/api-testing/step3/index.md ### Encryption and Decryption {#encryption-and-decryption} 1. If the endpoint you are calling requires [encryption or decryption](https://developer.mastercard.com/platform/documentation/security-and-authentication/securing-sensitive-data-using-payload-encryption/), you need to configure an interceptor to encrypt the request payload or decrypt the response body. 2. To configure the interceptor load the certificate, and create the configuration object for encryption. ```java private static FieldLevelEncryptionConfig getEncryptionConfig(String encryptionCertPath) { FieldLevelEncryptionConfig config = null; try { Certificate encryptionCertificate = EncryptionUtils.loadEncryptionCertificate(encryptionCertPath); config = FieldLevelEncryptionConfigBuilder .aFieldLevelEncryptionConfig() .withEncryptionCertificate(encryptionCertificate) .withEncryptionPath("$", "$") .withEncryptedValueFieldName("encryptedData") .withEncryptedKeyFieldName("encryptedKey") .withOaepPaddingDigestAlgorithmFieldName("oaepHashingAlgorithm") .withOaepPaddingDigestAlgorithm("SHA-256") .withEncryptionKeyFingerprintFieldName("publicKeyFingerprint") .withIvFieldName("iv") .withFieldValueEncoding(FieldLevelEncryptionConfig.FieldValueEncoding.HEX) .build(); } catch (Exception e) { // Log and resolve this error. } return config; } ``` 3. Create a configuration object for decryption. ```java public static FieldLevelEncryptionConfig decryptionConfig(String keyFile, String keyAlias, String password) { FieldLevelEncryptionConfig config = null; try { PrivateKey key = EncryptionUtils.loadDecryptionKey(keyFile, keyAlias, password); config = FieldLevelEncryptionConfigBuilder .aFieldLevelEncryptionConfig() .withDecryptionKey(key) .withDecryptionPath("$", "$") .withEncryptedValueFieldName("encryptedData") .withEncryptedKeyFieldName("encryptedKey") .withOaepPaddingDigestAlgorithmFieldName("oaepHashingAlgorithm") .withOaepPaddingDigestAlgorithm("SHA-256") .withEncryptionKeyFingerprintFieldName("publicKeyFingerprint") .withIvFieldName("iv") .withFieldValueEncoding(FieldLevelEncryptionConfig.FieldValueEncoding.HEX) .build(); } catch (Exception e) { // Log and resolve this error. } return config; } ``` 4. Instantiate IssuerApi with `getApiClient` with `enabledEncryptionDecryption` as true. ```Java IssuerApi issuerApiForEncryptionDecryption = new IssuerApi(getApiClient(true)); ``` 5. Use the below method to get ApiClient: ```java private static ApiClient getApiClient(boolean enabledEncryptionDecryption) throws Exception { ApiClient client = new ApiClient(); String consumerKey = ""; String signingKeyFilePath = ""; String encryptionCertPath = ""; String mcKeyFilePath = "" String signingKeyAlias = ""; String signingKeyPassword = ""; String mcKeyAlias = ""; String mcKeyPassword = ""; PrivateKey signingKey = AuthenticationUtils.loadSigningKey(signingKeyFilePath, signingKeyAlias, signingKeyPassword); client.setBasePath("https://stage.api.mastercard.com/cts"); client.setDebugging(false); if (enabledEncryptionDecryption) { client.setHttpClient(client.getHttpClient() .newBuilder() .addInterceptor(new OkHttpFieldLevelEncryptionInterceptor( getEncryptionConfig(encryptionCertPath))) .addInterceptor(new OkHttpFieldLevelEncryptionInterceptor( decryptionConfig(mcKeyFilePath,mcKeyAlias,mcKeyPassword))) .addInterceptor(new OkHttpOAuth1Interceptor(consumerKey, signingKey)) .build()); } else { client.setHttpClient(client.getHttpClient() .newBuilder() .addInterceptor(new OkHttpOAuth1Interceptor(consumerKey, signingKey)) .build()); } return client; } ```