Help Center> ServiceStage> FAQ> Java SDK FAQs> How Do I Extend AK/SK Decryption Methods?

How Do I Extend AK/SK Decryption Methods?

Problem

How do I extend AK/SK decryption methods?

Solution

Extend and implement AKSKCipher: implements com.huawei.paas.foundation.auth.credentials.AKSKCipher

Implement the name() and decode(TYPE type, char[] encrypted) methods, and use the @Component annotation to initialize the class as bean. TYPE is of the enumerated value, which can be AK or SK. Generally, only SK needs to be encrypted for storage.

An example is as follows:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
@Component
public class CustomAKSKDepl implements com.huawei.paas.foundation.auth.credentials.AKSKCipher {
    @Override
    public String name() {
        return "base64";
    }

    @Override
    public char[] decode(TYPE type, char[] encrypted) {
        try {
            String a = new String(Base64.decodeBase64(String.valueOf(encrypted)), "UTF-8");
            return a.toCharArray();
        }
        catch (UnsupportedEncodingException e) {
            return null;
        }
    }
}