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

191
Visualizações
try to generating signature using HMACSHA512 in c#

signature in c# using HMACSHA512 not equivalent to java and JavaScript. after tracing my c# code i found the key is not used during generating signature.

using System.Security.Cryptography;

using System.Text;

string privateKey = "OPAYPRV16388855997950.6319778282304234";

string message = "{\r\n  \"country\": \"EG\",\r\n  \"reference\": \"9cf357a79ffc4cb5a57cd0489a1a4bfa\"\r\n}";

byte[] messagebyte = Encoding.Default.GetBytes(message);
byte[] pkey =   Encoding.Default.GetBytes(privateKey);

HMACSHA512 hMACSHA512 = new HMACSHA512(pkey);

//hMACSHA512.Key = pkey; //other way and not give right signature

//hmacsha512.Initialize();

var hmac = hMACSHA512.ComputeHash(messagebyte);
var hmacres = BitConverter.ToString(hmac).Replace("-", "");

Console.WriteLine(hmacres);

// signature c# =FC96AABB47DE439A78CB98943BA3E9F9C25B24264E1431CC4180348F5B48C869F9003E3B67B8E387D25A7189093ACDD90205A103A489856379971EBE07E295E5

// signature in java and JavaScript (the same and the right signature)=
20c8b06951a7907b48db0ccb0b1fb514e8addb2b7c72786cc21316576d57e57560188cac837ffe232a9b24e65e73c6c05e6a5dddff3cc03e26521c92e74e064d 
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

HMACSHA512 deal with \r\n and spaces as characters, when remove /r/n and space I got the right signature

message= message.Replace(System.Environment.NewLine, string.Empty).Replace(" ", "");

byte[] messagebyte = Encoding.Default.GetBytes(message);

byte[] pkey = Encoding.Default.GetBytes(privateKey);

HMACSHA512 hMACSHA512 = new HMACSHA512(pkey);

var hmac = hMACSHA512.ComputeHash(messagebyte);

var hmacres = BitConverter.ToString(hmac).Replace("-", "");

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