Hàm băm mã hóa Base64 HMAC sha256 PHP
Tôi thực sự biết ơn về chức năng 8 nhưng có điều tôi không thể đạt được. Đó là xuất ra chuỗi giống như hàm hmac của PHP với chế độ “dữ liệu nhị phân thô” được bật Show
đầu ra.
đầu ra. 9Tất cả đều tốt, với chế độ dữ liệu mặc định (chữ thường hexits) Hugo và PHP nhận được kết quả tương tự. Thật không may, có vẻ như thứ tôi cần là đầu ra tôi nhận được với thông số sau trong đó tham số cuối cùng được đặt thành true (dữ liệu thô)
đầu ra. var crypto = require('crypto'); var key = 'the shared secret key here'; var message = 'the message to hash here'; var hash = crypto.createHmac('sha256', key).update(message); // to lowercase hexits hash.digest('hex'); // to base64 hash.digest('base64');1 Có cách nào để đạt được kết quả tương tự với Hugo không? Có, thứ tự đối số là đúng (khác với PHP) Đối với ngữ cảnh, tôi đang cố gắng hết sức để làm việc với Apple News API và chính sách bảo mật của họ yêu cầu 8 trên các tham số được nối khác nhau. Tôi có thể chuyển xác thực thành công bằng phương thức dữ liệu thô php, nhưng không phải với phương thức riêng của HugoĐầu tiên, nhập văn bản thuần túy và khóa mật mã để tạo mã. Sau đó, bạn có thể sử dụng chọn hàm băm mà bạn muốn áp dụng để băm. Mặc định là SHA-256. Sau đó, bạn có thể gửi yêu cầu của mình bằng cách nhấp vào nút băm tính toán để tạo mã xác thực HMAC cho bạn Theo mặc định, đầu ra ở định dạng văn bản thuần túy nhưng bạn cũng có tùy chọn để nhận đầu ra ở định dạng Base64. Dưới đây là một ảnh chụp màn hình của việc sử dụng đầu vào ví dụ BiếnValuekeyvar crypto = require('crypto'); var key = 'the shared secret key here'; var message = 'the message to hash here'; var hash = crypto.createHmac('sha256', key).update(message); // to lowercase hexits hash.digest('hex'); // to base64 hash.digest('base64');8message var crypto = require('crypto'); var key = 'the shared secret key here'; var message = 'the message to hash here'; var hash = crypto.createHmac('sha256', key).update(message); // to lowercase hexits hash.digest('hex'); // to base64 hash.digest('base64');9 Đầu ra tham chiếu cho đầu vào ví dụ ở trên LoạiHashas hexit_______50as base64require 'openssl' key = 'the shared secret key here' message = 'the message to hash here' # to lowercase hexits OpenSSL::HMAC.hexdigest('sha256', key, message) # to base64 Base64.encode64(OpenSSL::HMAC.digest('sha256', key, message))1 PHP
$key = 'the shared secret key here';
$message = 'the message to hash here';
// to lowercase hexits
hash_hmac('sha256', $message, $key);
// to base64
base64_encode(hash_hmac('sha256', $message, $key, true)); NodeJSvar crypto = require('crypto'); var key = 'the shared secret key here'; var message = 'the message to hash here'; var hash = crypto.createHmac('sha256', key).update(message); // to lowercase hexits hash.digest('hex'); // to base64 hash.digest('base64'); hồng ngọcrequire 'openssl' key = 'the shared secret key here' message = 'the message to hash here' # to lowercase hexits OpenSSL::HMAC.hexdigest('sha256', key, message) # to base64 Base64.encode64(OpenSSL::HMAC.digest('sha256', key, message)) tiên dược 0Đi 1Trăn 2 2Trăn 3 3C# 4Java 5đầu vào ví dụ Thông báo giá trị biến____39Đầu ra tham chiếu cho đầu vào ví dụ ở trên LoạiHashas hexit____53as base64require 'openssl' key = 'the shared secret key here' message = 'the message to hash here' # to lowercase hexits OpenSSL::HMAC.hexdigest('sha256', key, message) # to base64 Base64.encode64(OpenSSL::HMAC.digest('sha256', key, message))4 PHP 9NodeJSvar crypto = require('crypto'); var key = 'the shared secret key here'; var message = 'the message to hash here'; var hash = crypto.createHmac('sha256', key).update(message); // to lowercase hexits hash.digest('hex'); // to base64 hash.digest('base64');0 hồng ngọcvar crypto = require('crypto'); var key = 'the shared secret key here'; var message = 'the message to hash here'; var hash = crypto.createHmac('sha256', key).update(message); // to lowercase hexits hash.digest('hex'); // to base64 hash.digest('base64');1 tiên dượcvar crypto = require('crypto'); var key = 'the shared secret key here'; var message = 'the message to hash here'; var hash = crypto.createHmac('sha256', key).update(message); // to lowercase hexits hash.digest('hex'); // to base64 hash.digest('base64');2 Đivar crypto = require('crypto'); var key = 'the shared secret key here'; var message = 'the message to hash here'; var hash = crypto.createHmac('sha256', key).update(message); // to lowercase hexits hash.digest('hex'); // to base64 hash.digest('base64');3 Trăn 2var crypto = require('crypto'); var key = 'the shared secret key here'; var message = 'the message to hash here'; var hash = crypto.createHmac('sha256', key).update(message); // to lowercase hexits hash.digest('hex'); // to base64 hash.digest('base64');4 Trăn 3var crypto = require('crypto'); var key = 'the shared secret key here'; var message = 'the message to hash here'; var hash = crypto.createHmac('sha256', key).update(message); // to lowercase hexits hash.digest('hex'); // to base64 hash.digest('base64');5 C#var crypto = require('crypto'); var key = 'the shared secret key here'; var message = 'the message to hash here'; var hash = crypto.createHmac('sha256', key).update(message); // to lowercase hexits hash.digest('hex'); // to base64 hash.digest('base64');6 Javavar crypto = require('crypto'); var key = 'the shared secret key here'; var message = 'the message to hash here'; var hash = crypto.createHmac('sha256', key).update(message); // to lowercase hexits hash.digest('hex'); // to base64 hash.digest('base64');7 Làm cách nào để giải mã HMAC sha256 trực tuyến?Đầu tiên, nhập văn bản thuần túy và khóa mật mã để tạo mã. Sau đó, bạn có thể sử dụng chọn hàm băm mà bạn muốn áp dụng để băm. Mặc định là SHA-256. Sau đó, bạn có thể gửi yêu cầu của mình bằng cách nhấp vào nút băm tính toán để tạo mã xác thực HMAC cho bạn
Làm cách nào để giải mã hash_hmac trong PHP?hash_hmac là hàm băm, không phải hàm mã hóa. Bạn sẽ không thể giải mã nó. Thay vào đó, bạn nên sử dụng mô-đun Mcrypt .
HMAC 256 là gì?HMACSHA256 là một loại thuật toán băm có khóa được xây dựng từ hàm băm SHA-256 và được sử dụng làm Mã xác thực thư dựa trên hàm băm (HMAC). |