Yêu cầu thg 7 13, 2022 2:47 SA 99 0 1
  • 99 0 1
0

Mình có đoạn code java để mã hóa secretkey , mình muốn chuyển nó qua php

Chia sẻ
  • 99 0 1

public String makeFingerprint(String method, String uri, long timestamp) throws Exception { String space = " "; // one space String newLine = "\n"; // new line

	String message = new StringBuilder() //
			.append(method) // 'GET'
			.append(space) //
			.append(uri) // '/api/product/count?searchTarget=productName&searchQuery=Test'
			.append(newLine) //
			.append(timestamp) //
			.append(newLine) //
			.append(accessKey) //
			.toString();

	SecretKeySpec signingKey = new SecretKeySpec(secretKey.getBytes("UTF-8"), "HmacSHA256");
	Mac mac = Mac.getInstance("HmacSHA256");
	mac.init(signingKey);

	byte[] rawHmac = mac.doFinal(message.getBytes("UTF-8"));
	String encodeBase64String = Base64.encodeBase64String(rawHmac);

	return encodeBase64String;

}

1 CÂU TRẢ LỜI


Đã trả lời thg 7 22, 2022 3:10 SA
Đã được chấp nhận
0

Bạn thử như vậy xem nhé:

$message = "{$method}{$space}{$uri}{$newLine}{$timestamp}{$newLine}{$accessKey}";
$hex = hash_hmac('sha256', $message, $secretKey);
$encodeBase64String = base64_encode($hex);
Chia sẻ
Avatar trungle @o0nobita
thg 7 22, 2022 6:43 SA

chuẩn r bạn ơi

Viblo
Hãy đăng ký một tài khoản Viblo để nhận được nhiều bài viết thú vị hơn.
Đăng kí