Versions Compared
compared with
Key
- This line was added.
- This line was removed.
- Formatting was changed.
Node.js
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
var crypto = require('crypto'); var hash = crypto.createHmac('SHA256', "portalKey").update("dataToBeSigned").digest('base64'); |
PHP
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
$s = hash_hmac('sha256', 'dataToBeSigned', 'portalKey', true); echo base64_encode($s); |
Java
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; import org.apache.commons.codec.binary.Base64; public class ApiSecurityExample { public static void main(String[] args) { String portalKey = "123456789987654321"; String dataToBeSigned= "18333183342111222LIVEuniqueReference100EUR"; Mac sha256_HMAC = Mac.getInstance("HmacSHA256"); SecretKeySpec secret_key = new SecretKeySpec(portalKey.getBytes(), "HmacSHA256"); sha256_HMAC.init(secret_key); String hash = Base64.encodeBase64String(sha256_HMAC.doFinal(dataToBeSigned.getBytes())); } } |
Ruby
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
require 'openssl' require "base64" hash = OpenSSL::HMAC.digest('sha256', "portalKey", "dataToBeSigned") putstoken = Base64.encode64(hash) token.delete("\n") |
Python
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
import hashlib import hmac import base64 dataToBeSigned= bytes("18333183342111222LIVEuniqueReference100EUR").encode('utf-8') portalKey = bytes("123456789987654321").encode('utf-8') signature = base64.b64encode(hmac.new(portalKey, dataToBeSigned, digestmod=hashlib.sha256).digest()) |
Table of Contents | ||
---|---|---|
|