Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

180
Visualizações
PHP - Create Signature using Nonce & Timestamp (JS & Python equivalent provided)

I'm trying to connect to an API and they only provide guides for python & Javascript. I'm trying to find the equivalent for php but coming up short.

For additional reference: https://docs.deribit.com/#authentication

I'm unable to get the proper signature in PHP.

Javascript:

var timestamp = Date.now();
var nonce = "abcd";
var data = "";
var signature = CryptoJS.HmacSHA256(`${timestamp}\n${nonce}\n${data}`, accessSecret).toString();

Python:

timestamp = round(datetime.now().timestamp() * 1000)
nonce = "abcd"
data = ""
signature = hmac.new(
    bytes(clientSecret, "latin-1"),
    msg=bytes('{}\n{}\n{}'.format(timestamp, nonce, data), "latin-1"),
    digestmod=hashlib.sha256
).hexdigest().lower()

PHP: (*I don't know how to create the nonce)

$timestamp = number_format(microtime(true) * 1000, 0, '.', '');
$nonce = number_format(microtime(true) * 1000, 0, '.', '');
$data = "";

$key = $timestamp.$nonce.$data;
$sign = hash_hmac('sha256',$key,$secret);
$sign = bin2hex($sign);
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

For the random generation required 'a-z0-9', 8 characters you may please use chr and rand to do the job.

Hence try the following

<?php
$x1=   chr(rand(0,25)+97) ;
$x2=   chr(rand(0,9)+48) ;
$x3=   chr(rand(0,25)+97) ;
$x4=   chr(rand(0,9)+48) ;
$x5=   chr(rand(0,25)+97) ;
$x6=   chr(rand(0,9)+48) ;
$x7=   chr(rand(0,25)+97) ;
$x8=   chr(rand(0,9)+48) ;

$nonce = $x1.$x2.$x3.$x4.$x5.$x6.$x7.$x8;

?>
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda