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.
Parameter | Tipe | Deskripsi | Request Header |
---|---|---|---|
client_code | string | Unique Client ID yang disediakan Prakerja ke DP / LP. Prakerja akan menyediakan credential yaitu kombinasi client_code dan sign_key ke DP / LP. |
|
timestamp | number | 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 Timestamp digunakan di --header 'timestamp:' yang nilainya harus sama persis dengan timestamp yang digunakan untuk membuat signature. |
|
method | string | Request HTTP Method
| |
url_path_endpoint | string | /uri/path API
| |
body_payload | string | Contoh
|
Contoh raw_signature di API /api/v1/integration/payment/redeem-code/status:
client_code1698289216POST/api/v1/integration/payment/redeem-code/status{"redeem_code":"GHOPNYXUVMT0","sequence":1}
Proses hashing
Proses hashing menggunakan algoritma HMAC-SHA1 dengan sign_key yang disediakan Prakerja ke DP / LP:
Input | Proses | Output |
---|---|---|
raw_signature |
| 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