You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

NetSuite SuiteScript 2.0字符串SHA1转BASE64编码报错求助

Fixing SuiteScript 2.0 SHA1 + Base64 Encoding Error

You're running into this error:

WrappedException: Wrapped java.lang.IllegalArgumentException: contains illegal character for hexBinary: crypto.SecretKey

Let's break down why this is happening and fix your code.

The Root Cause

Your code misuses HTTPS.createSecretKey() — this method is meant for creating secret keys from GUIDs or raw data, not converting a hashed SecureString to a hexadecimal string. When you pass the hashed SecureString directly to the guid parameter, you're passing a crypto.SecretKey object instead of a valid hex string, which triggers the illegal character error.

Corrected Code

Here's the working version that correctly executes your required steps (SHA1 hex hash → Base64 encode):

// Assume nonce, timestamp, secret are pre-defined variables
var str = nonce + timestamp + secret;
var secureString = HTTPS.createSecureString({ input: str });

// Step 1: Compute SHA1 hash of the input string
var hashedSecureString = secureString.hash({ algorithm: CRYPTO.HashAlg.SHA1 });

// Convert the hashed SecureString to a hexadecimal string
var hexString = hashedSecureString.toString({ encoding: HTTPS.Encoding.HEX });

// Step 2: Encode the hex string to Base64
var digest = ENCODE.convert({
    string: hexString,
    inputEncoding: ENCODE.Encoding.HEX,
    outputEncoding: ENCODE.Encoding.BASE_64
});

What Changed?

  • Hex string conversion: Instead of HTTPS.createSecretKey(), we use hashedSecureString.toString({ encoding: HTTPS.Encoding.HEX }) — this is the correct way to get a hexadecimal representation of a hashed SecureString in SuiteScript 2.0.
  • Valid input for Base64 conversion: Now hexString is a plain text hex string, which ENCODE.convert() can properly process without throwing errors.

内容的提问来源于stack exchange,提问作者david_85

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 04:02:33