com.aliyun.openservices.ons.api.impl.authority.AuthUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gw-boot-starter-aliyun-ons Show documentation
Show all versions of gw-boot-starter-aliyun-ons Show documentation
A Java Utils Libraray By Geewit
package com.aliyun.openservices.ons.api.impl.authority;
import com.aliyun.openservices.shade.com.alibaba.rocketmq.remoting.protocol.RemotingCommand;
import java.util.SortedMap;
import static com.aliyun.openservices.ons.api.impl.authority.SessionCredentials.CHARSET;
public class AuthUtil {
public static byte[] combineRequestContent(RemotingCommand request, SortedMap fieldsMap) {
try {
StringBuilder sb = new StringBuilder();
fieldsMap.forEach((key, value) -> {
if (!SessionCredentials.Signature.equals(key)) {
sb.append(value);
}
});
return AuthUtil.combineBytes(sb.toString().getBytes(CHARSET), request.getBody());
} catch (Exception e) {
throw new RuntimeException("incompatible exception.", e);
}
}
public static byte[] combineBytes(byte[] b1, byte[] b2) {
int size = (null != b1 ? b1.length : 0) + (null != b2 ? b2.length : 0);
byte[] total = new byte[size];
if (null != b1) {
System.arraycopy(b1, 0, total, 0, b1.length);
}
if (null != b1 && null != b2) {
System.arraycopy(b2, 0, total, b1.length, b2.length);
}
return total;
}
public static String calSignature(byte[] data, String secretKey) {
String signature = OnsAuthSigner.calSignature(data, secretKey);
return signature;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy