Generate Signature

Signature digunakan sebagai parameter request header, setiap kali DP / LP melakukan hit API apapun di Prakerja. Penting bagi DP / LP memperhatikan dengan seksama bagaimana cara membuat Signature.

1curl --location -g --request POST 'URL' \
2--header 'signature: {{request_signature}}'

Signature dibuat dari raw_signature yang di-hashing menggunakan algoritma HMAC-SHA1 dengan sign_key yang disediakan Prakerja ke DP / LP

Membuat raw_signature

Struktur raw_signature terdiri dari parameter.

ParameterTipeDeskripsiRequest Header
client_codestringUnique Client ID yang disediakan Prakerja ke DP / LP.
Prakerja akan menyediakan credential yaitu kombinasi client_code dan sign_key ke DP / LP.
1--header 'client_code: client_code'
timestampnumber

Format nilai waktu dalam satuan detik yang digunakan saat melakukan hit API

Contoh 1698289216 = 26-10-2023 10:00:16 WIB = 2023-10-26T10:00:16+07:00

1--header 'timestamp: timestamp'
methodstringRequest HTTP Method
  • POST
url_path_endpointstring/uri/path API
  • /api/v1/integration/payment/redeem-code/status
  • /api/v1/integration/oauth/url-generate
  • /api/v1/integration/payment/redeem-code/reset
body_payloadstringContoh
1{"redeem_code":"GHOPNYXUVMT0","sequence":1}

Contoh raw_signature di API /api/v1/integration/payment/redeem-code/status:

Proses hashing

Proses hashing menggunakan algoritma HMAC-SHA1 dengan sign_key yang disediakan Prakerja ke DP / LP:

InputProsesOutput
raw_signature
1signature = toHex(
2  SHA-1(
3    raw_signature,
4    sign_key
5  )
6)
signature
sign_key
Try This!
 
Example Code
1// Generated by Prakerja Generator
2// for complete documentation please visit https://developer.prakerja.go.id
3
4const crypto = require('crypto-js');
5
6const redeem_code = ''; // redeem code generated by system when user buy training
7
8const client_code = ''; // provided by Prakerja
9const timestamp = Math.round((new Date()).getTime() / 1000); // generate current timestamp
10const method = ''; // API Method
11const endpoint = ''; // API Redeem Status Endpoint
12
13const data = {};
14
15const input = client_code + timestamp + method + endpoint + JSON.stringify(data); // create signature input
16const sign_key = ''; // provided by Prakerja
17
18const signature = crypto.HmacSHA1(input, sign_key).toString(crypto.enc.Hex); // generate signature
19
20console.log('signature:', signature);
1<?php
2// Generated by Prakerja Generator
3// for complete documentation please visit https://developer.prakerja.go.id
4
5$redeem_code = ''; // redeem code generated by system when user buy training
6
7$client_code = ''; // provided by Prakerja
8$timestamp = time(); // generate current timestamp
9$method = ''; // API Method
10$endpoint = ''; // API Redeem Status Endpoint
11
12$data = [];
13
14$input = $client_code . $timestamp . $method . $endpoint . json_encode($data); // create signature input
15$sign_key = ''; // provided by Prakerja
16
17$signature = hash_hmac('sha1', $input, $sign_key); // generate signature
18
19print_r('signature: ' . $signature);
1# Generated by Prakerja Generator
2# for complete documentation please visit https://developer.prakerja.go.id
3
4from hashlib import sha1
5import hmac
6import time
7import json
8
9redeem_code = '' # redeem code generated by system when user buy training
10
11client_code = '' # provided by Prakerja
12timestamp = str(int(time.time())) # generate current timestamp
13method = '' # API Method
14endpoint = '' # API Redeem Status Endpoint
15
16data = {}
17
18# create signature input
19input = client_code + timestamp + method + endpoint + json.dumps(data, separators=(',', ':'))
20
21sign_key = '' # provided by Prakerja
22
23# generate signature
24signature = hmac.new(sign_key.encode("utf-8"), input.encode("utf-8"), sha1).hexdigest()
25
26print('signature: ' + signature)
1# Generated by Prakerja Generator
2# for complete documentation please visit https://developer.prakerja.go.id
3
4require 'openssl'
5require 'json'
6
7redeem_code = '' # redeem code generated by system when user buy training
8
9client_code = '' # provided by Prakerja
10timestamp = String(Time.now.to_i) # generate current timestamp
11method = '' # API Method
12endpoint = '' # API Redeem Status Endpoint
13
14data = {}
15
16# create signature input
17input = client_code + timestamp + method + endpoint + JSON.generate(data, quirks_mode: true)
18
19key = '' # provided by Prakerja
20
21signature = OpenSSL::HMAC.hexdigest(OpenSSL::Digest::Digest.new('sha1'), key.encode("ASCII"), input.encode("ASCII"))
22
23puts 'signature: ' + signature