Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


Node.js

Code Block
languagejs
themeMidnight
titleHmac SHA256
var crypto = require('crypto');
var hash = crypto.createHmac('SHA256', "portalKey").update("dataToBeSigned").digest('base64');

PHP

Code Block
languagephp
themeMidnight
titleHmac SHA256
$s = hash_hmac('sha256', 'dataToBeSigned', 'portalKey', true);
echo base64_encode($s);

Java

Code Block
languagejava
themeMidnight
titleHmac SHA256
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
languageruby
themeMidnight
titleHmac SHA256
require 'openssl'
require "base64"

hash  = OpenSSL::HMAC.digest('sha256', "portalKey", "dataToBeSigned")
putstoken = Base64.encode64(hash)
token.delete("\n")

Python

Code Block
languagepy
themeMidnight
titleHmac SHA256
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
indent2em