Introduction
Integration Guide
- Integration Preparation
- Core Mechanism
- API General Instructions
- Request Examples
- Response Examples
- Core Utility Classes
- Frequently Asked Questions
System Flowchart
Checkout
API List
Response Examples
Decryption Operation Guide
WaaS API Response Data Decryption Operation Guide
c. Decryption Operation Guide
This guide details how to decrypt encrypted response data obtained from WaaS APIs.
i. Decryption Process Step-by-Step Explanation
The following are the steps for decryption operations:
- Obtain encrypted data from the API response
- Perform Base64 decoding of the data
- Decrypt using the RSA public key
- Parse the decrypted result into the business object
ii. Decryption Code Examples
Copy
class DecryptionExample {
public static void main(String[] args) {
try {
// ===================== 1. Get API response =====================
// Send API request and get response
APIResult response = restTemplate.postForObject(
"https://waas2-out-api.powersafe-rel.cc/api/v1/api/user/getUserAddress",
httpEntity,
APIResult.class
);
// Extract encrypted data (ensure response format matches API)
String encryptedData = response.getData();
// ===================== 2. Base64 decoding =====================
// Decode using Base64 utility class (implementation reference utility classes)
byte[] decodedBytes = Base64Util.decodeString(encryptedData);
// ===================== 3. RSA public key decryption =====================
// Use the same public key as for requests
String publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQ...";
// Perform RSA decryption
byte[] decryptedBytes = RSAUtils.decryptByPublicKey(
decodedBytes,
publicKey
);
// ===================== 4. Parse business object =====================
// Convert decrypted JSON data to business object
AddressVO address = JsonUtils.fromJson(
new String(decryptedBytes, StandardCharsets.UTF_8),
AddressVO.class
);
// ===================== 5. Use decrypted data =====================
System.out.println("Parsed address information:");
System.out.println("Merchant user ID: " + address.getTenantUserId());
System.out.println("Chain name: " + address.getChainName());
System.out.println("Wallet address: " + address.getAddress());
System.out.println("Tag: " + address.getTag());
System.out.println("State: " + address.getState());
System.out.println("Risk score: " + address.getRiskScore());
} catch (Exception e) {
System.err.println("\nError occurred during decryption: " + e.getMessage());
e.printStackTrace();
}
}
}
Assistant
Responses are generated using AI and may contain mistakes.