in Server/java/src/main/java/com/company/apptoken/model/AppToken.java [49:84]
public String buildTokenString() throws Throwable {
if (StringUtils.isBlank(this.appKey)) {
throw new IllegalArgumentException("missing secretKey");
}
if (Objects.isNull(this.service)) {
throw new IllegalArgumentException("missing service");
}
final byte[] signatureTemp = SignatureUtils.sign(this.appKey, this.issueTimestamp, this.salt);
final ByteBuf buf = Unpooled.buffer();
final byte[] appId = this.appId.getBytes();
buf.writeInt(appId.length);
buf.writeBytes(appId);
buf.writeInt(this.issueTimestamp);
buf.writeInt(this.salt);
buf.writeInt(this.timestamp);
this.service.pack(buf);
if (Objects.isNull(this.options)) {
this.options = new AppTokenOptions();
}
this.options.pack(buf);
final Mac mac = Mac.getInstance(SecurityConstants.ALGORITHM_HMAC_SHA256);
mac.init(new SecretKeySpec(signatureTemp, SecurityConstants.ALGORITHM_HMAC_SHA256));
final byte[] signature = mac.doFinal(buf.array());
final ByteBuf bufToken = Unpooled.buffer();
bufToken.writeInt(signature.length);
bufToken.writeBytes(signature);
bufToken.writeBytes(buf.array());
return AppTokenConstants.VERSION_0 + EncodeUtils.base64Encode(CompressUtils.compress(bufToken.array()));
}