简体   繁体   English

将 JS crypto.createHmac 翻译成 Xojo Crypto.HMAC

[英]Translating JS crypto.createHmac to Xojo Crypto.HMAC

I am trying to translate this block in Javascript:我正在尝试在 Javascript 中翻译这个块:

const crypto = require('crypto'),
    shared_key = 'kw4qSnpSwXzgiv5yxYpZZmFEd9QAeiKTQ6OuyMja',
    signing_string = 'licenseSpring\ndate: Tue, 07 Jun 2011 20:51:35 GMT';

let signature = crypto.createHmac('sha256', shared_key).update(signing_string).digest('base64');

console.log(signature);
// UDysfR6MndUZReo07Y9r+vErn8vSxrnQ5ulit18iJ/Q=

Into Xojo:走进Xojo:

Var shared_key as String = "kw4qSnpSwXzgiv5yxYpZZmFEd9QAeiKTQ6OuyMja"
Var signing_string as String =  "licenseSpring\ndate: Tue, 07 Jun 2011 20:51:35 GMT"

Var hash As String
hash = EncodeBase64(Crypto.HMAC(shared_key, signing_string, Crypto.HashAlgorithms.SHA256))
MessageBox(hash)
//Q4BAhsu1Xw3LsBZ+BCLShWQDbmJ2j/eFXzvF9T6n9tU=

I am getting two different hashed strings, but expect they should be the same.我得到两个不同的散列字符串,但希望它们应该是相同的。 Are these algorithms equivalent?这些算法是否等效?

It turned out to be this:原来是这样的:

Var signing_string as String =  "licenseSpring" + EndOfLine.UNIX + "date: Tue, 07 Jun 2011 20:51:35 GMT"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我的crypto.createHmac()为相同的输入生成不同的HMAC? - Why does my crypto.createHmac() generate a different HMAC for the same input? 为什么我的crypto.createHmac()为相同的输入生成不同的HMAC? - Why does my crypto.createHmac() generate a different HMAC for the same input? 需要与 crypto.createHmac 方法的这个特定实现等效的浏览器 - Need browser equivalent of this specific implementation of crypto.createHmac method HOTP 问题:Node.js crypto.createHmac 仅在计数为 0 时有效 - HOTP issue: Node.js crypto.createHmac works only when count is 0 使用angular 4获得TypeError的woocommerce集成:crypto.createHmac不是函数 - Integration of woocommerce using angular 4 getting TypeError: crypto.createHmac is not a function 如何在浏览器中复制Node的Crypto.createHmac('sha256',buffer)? - How to replicate Node's Crypto.createHmac( 'sha256', buffer) in the browser? 将 crypto hmac 转换为 crypto-js hmac 字符串 - Converting crypto hmac to crypto-js hmac string 将哈希HMAC SHA256的端口JS加密代码移植到PHP - Port JS crypto code for hash HMAC SHA256 to PHP 如何将数字传递给crypto-js hmac sha1方法? - How to pass number to crypto-js hmac sha1 method? 在 C# 中重新组装加密 hmac 代码 - Reassemble crypto hmac code in C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM