Signature v1 (Deprecated)
TIP
To be terminated since 2024 March 01
Process
1.
2.
3.
4.
Construct the data to be signed
{
"key1"=value1, //int
"key2"="value2", //string
}
Global Parameters
body
query
stringParameter | Example | Data Type | Description |
---|---|---|---|
timestamp | 1640917845984 | String | Epoc time UTC0 timestamp in millisecond. Maximum time difference allowed by the server is 10 minutes. |
nonce | 23 | Integer | Random positive integer |
{"timestamp":1674197059220,nonce:13} //NOTE that nonce is Integer
Path Parameters
//for example: /sims/{sim_id}/usage
{"sim_id":"892030318384848290"}
Query Parameters
//for example: ?begin_from=2023-01&type=1
{"begin_from":"2023-01","type":1}
Body
The data structure
api:
GET /sims/{sim_id}/usage
GET https://api.linksfield.net/cube/v4/sims/89852002021102915651/usage?begin_from=2023-01&category=data&end_by=2023-01&period_type=2×tamp=1674197059220&nonce=128
{"begin_from":"2023-01","category_type":"data","end_by":"2023-01","nonce":128,"period_type":2,"sim_id":"89852002021102915651","timestamp":"1674197059220"}
1.
2.
\n
, \t
etc.3.
timestamp
is String
type and nonce
is Integer
typeThe coding examples
Java
Python
# Author:luoyang
from Crypto.PublicKey import RSA
from Crypto.Hash import SHA
from Crypto.Signature import PKCS1_v1_5 as Sig_pk
import base64
import os
import json
#
def get_sign(data):
"""
sign
"""
path = os.path.dirname(os.path.abspath(__file__))
doc = os.path.join(path, 'private.pem')
with open(doc) as pk:
key_data = pk.read()
# private key
rsakey = RSA.importKey(key_data)
# sha
print("data:", data)
en_data = SHA.new(data.encode())
# sign
sig_pk = Sig_pk.new(rsakey)
sign = sig_pk.sign(en_data)
# base64
result = base64.b64encode(sign)
# result
data = result.decode()
print("decode-sign:", data)
return data
# format
def format_data(data):
return data.replace(' ','')
#
if __name__ =='__main__':
data ={
"title":"4.0",
"timestamp":"1493893971",
"query_type":"imei",
"value":"12345"
}
sx_data = json.dumps(data, sort_keys=True, ensure_ascii=False)
fdata = format_data(sx_data)
get_sign(fdata)
JavaScript
postman, apifox
//TODO might not accomodate nested json object..!!
paramsString = JSON.stringify(params, Object.keys(params).sort());
console.log("sorted string to sign:", paramsString);
//get key
var rsa = require('jsrsasign');
var pem = privateKey;
try {
var keyhex = rsa.pemtohex(pem, "RSA PRIVATE KEY");
var rsakey = rsa.KEYUTIL.getKeyFromPlainPrivatePKCS8Hex(keyhex);
} catch (e) {
console.log("key error:", e);
}
var sig = new rsa.KJUR.crypto.Signature({ "alg": "SHA1withRSA" });
sig.init(rsakey);
sig.updateString(paramsString);
try {
var sign = sig.sign();
sign = rsa.hextob64(sign);
//token
var token = "LF " + accessKeyId + "/" + sign;
pm.environment.set("lfToken", token);
} catch (e) {
console.log("sign error:", e);
}
Modified at 2025-02-18 01:10:12