我需要在php中计算api集成的摘要,但是我有java中的摘要计算代码,有谁能帮助我在php中得到它的等价物吗。
import org.joda.time.DateTime;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.codec.binary.Hex;
public class Helper {
public static String getDigest(String publicKey, String privateKey, String requestMethod, String version) {
String result = null;
String ALGORITHM = "HmacSHA256";
long time = DateTime.now(DateTimeZone.UTC).getMillis();
StringBuffer baseString = new StringBuffer(requestMethod);
baseString.append(publicKey);
baseString.append(version);
baseString.append(nowAsDateTime().getMillis());
SecretKeySpec signingKey = new SecretKeySpec(privateKey.getBytes(), ALGORITHM);
try {
Mac mac = Mac.getInstance(ALGORITHM);
mac.init(signingKey);
result = Hex.encodeHexString(mac.doFinal(baseString.toString().getBytes()));
}
catch ( Exception e ) {
log.error("Exception in getDigest()", e);
throw new RuntimeException(e);
}
return result;
}
}
感谢您的帮助
暂无答案!
目前还没有任何答案,快来回答吧!