Android hamc 算法,知道进来帮帮忙 =======================

-船长- -船长- 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
这是服务器 HMAC的算法,我不知道怎么在Android实现。

/**
* Calculate the HMAC for the http request.
* This function signs an api request using the information provided. The signature returned
* has been base64 encoded and then url encoded.
*
* @param string $algo The HMAC algorithm used
* @param string $time String representation of unix time
* @param string $nonce Nonce
* @param string $api_key Your api key
* @param string $secret_key Your private key
* @param string $get_variables URLEncoded string representation of the get variable parameters,
* eg "method=user&guid=2"
* @param string $post_hash Optional sha1 hash of the post data.
*
* @return string The HMAC signature
* @access private
*/
function calculate_hmac($algo, $time, $nonce, $api_key, $secret_key,
$get_variables, $post_hash = "") {

global $CONFIG;

elgg_log("HMAC Parts: $algo, $time, $api_key, $secret_key, $get_variables, $post_hash");

$ctx = hash_init(map_api_hash($algo), HASH_HMAC, $secret_key);

hash_update($ctx, trim($time));
hash_update($ctx, trim($nonce));
hash_update($ctx, trim($api_key));
hash_update($ctx, trim($get_variables));
if (trim($post_hash) != "") {
hash_update($ctx, trim($post_hash));
}

return urlencode(base64_encode(hash_final($ctx, true)));
}



这是我实现的方法,但是就是通过不了服务器的验证:
try {
MessageDigest sha1 = MessageDigest.getInstance("SHA-1");
sha1.update(EncodingUtils.getAsciiBytes(PUBLIC_API_KEY));
sha1.update(EncodingUtils.getAsciiBytes(time));
sha1.update(EncodingUtils.getAsciiBytes(nonce));
sha1.update(EncodingUtils.getAsciiBytes(PRIVATE_API_KEY));
hmac = new String(Base64.encode(sha1.digest(), 0));
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
...全文

相关推荐

工地卸料平台扬尘安全管控建设方案(含设备选型清单).docx

工地卸料平台扬尘安全管控建设方案(含设备选型清单)

虎王科技

Image32适配丘老板的AIC8800D80更改固件路径20261202-1318.7z 韦东山CM5开发板RK3576 适配了type-C YT8521S AIC8800D80

Image32适配丘老板的AIC8800D80更改固件路径20261202_1318.7z 韦东山CM5开发板RK3576 适配了type-C YT8521S AIC8800D80 rk3576_linux6.1_release_v1.3.0_20251220.tar.gz aic8800d_linux_sdk_V4.0_2025_0808_54809c22.7z

南棱笑笑生

建筑给排水施工成本控制实施方案.docx

建筑给排水施工成本控制实施方案

虎王科技

大型央企集团在采购外部先进技术时,通常通过哪些公开的技术交易平台进行寻源?.docx

科易网(厦门科易网科技有限公司)创立于2007年,是技术转移与科技创新数智化服务平台,拥有国家科技成果转化服务示范基地、国家技术转移示范机构等资质。平台以“AI+科技成果转化”为核心,整合成果、专利、专家、政策等多维数据,构建知识图谱与科创智能体,面向企业、政府、高校院所提供成果转化、技术需求对接、产业服务等数智化解决方案。截至目前,已服务全国企业超43万家,推动落地项目11800余项,总金额逾80亿元

BIZKEEN

Agent原理解说与实践指导.zip

Agent原理解说与实践指导,与从零构建Agent-合集。着重介绍agent的原理以及实践

紫神
评论 1
收藏 已收藏
分享
返回顶部
-船长-
基础编程 21,889 成员 140,329 内容