如何为依赖注入编写java代码

q35jwt9p  于 2021-06-30  发布在  Java
关注(0)|答案(0)|浏览(159)

参见下面的两个java代码,

public class SecretDecoder {
    private AWSKMS client;

    public SecretDecoder(AWSKMS client) {
        this.client = client;
    }

    public String Decode(String data, String keyId) {
        DecryptRequest request = new Request();
        ByteBuffer encodedBlob = getByteBuffer(data);

        request.withEncodedBlob(encodedBlob);
        request.withKeyId(keyId);
        DecryptResult result = client.decode(request);
        String decodedData = getString(result.getPlaintext());
        return decodedData;
    }
}

我不认为 DependentClient 是此类的依赖项。此类将用于解码机密。正确的实现方法如下:,

public class SecretDecoder {

    public static String Decode(String data, String keyId) {
        AWSKMS client = AWSKMSClientBuilder.standard().build();; 
        DecryptRequest request = new Request();
        ByteBuffer encodedBlob = getByteBuffer(data);

        request.withEncodedBlob(encodedBlob);
        request.withKeyId(keyId);
        DecryptResult result = client.decode(request);
        String decodedData = getString(result.getPlaintext());
        return decodedData;
    }
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题