protected static String signature()

in aliyun-sdk-opensearch/src/main/java/com/aliyun/opensearch/auth/OpenSearchAuthentication.java [258:285]


    protected static String signature(String toSignContent, String secret) {
        Preconditions.checkNotNull(secret);
        byte[] keyBytes;
        try {
            keyBytes = secret.getBytes("UTF-8");
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException("JVM NOT SUPPORT UTF-8?");
        }
        SecretKey secretKeySpec = new SecretKeySpec(keyBytes, "HmacSHA1");
        Mac mac;
        try {
            mac = Mac.getInstance("HmacSHA1");
        } catch (NoSuchAlgorithmException e1) {
            throw new RuntimeException("JVM NOT SUPPORT Algorithm: HmacSHA1?");
        }
        try {
            mac.init(secretKeySpec);
        } catch (InvalidKeyException e1) {
            throw new RuntimeException(e1);
        }
        byte[] text;
        try {
            text = toSignContent.getBytes("UTF-8");
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException("JVM NOT SUPPORT UTF-8?");
        }
        return BaseEncoding.base64().encode(mac.doFinal(text));
    }