团队,
我有一个要求加密密码使用Neoload SHA512之前调用登录请求。谁能分享你的经验如何最好我们可以做同样的事情?
(最初要求和解决支持中心)
最佳答案社区管理员
\/\/ Get variable value from VariableManager
var MYPASSWORD = context.variableManager.getValue(\"myPassword\");
\/\/ Function to encrypt into sha512
function sha512(password) {
var hash = java.security.MessageDigest.getInstance(\"SHA-512\");
var encodedPassword =
java.nio.charset.StandardCharsets.UTF_8.encode(password);
hash.update(encodedPassword);
var encryptedPassword = hash.digest();
var hexString = new java.lang.StringBuilder();
for (var i = 0; i < encryptedPassword.length; i++) {
var hex = (encryptedPassword[i] & 0xff).toString(16);
if (hex.length === 1) {
hexString.append('0');
}
hexString.append(hex);
}
return hexString.toString();
}
\/\/ Run the function
const hashedPassword = sha512(MYPASSWORD);
\/\/ Log out for debugging (optional)
logger.error(\"SHA512=\"+hashedPassword);
\/\/ Inject the computed value in a runtime variable
context.variableManager.setValue(\"myPassword\",hashedPassword);<\/code><\/pre>Here's an example my setup:
<\/p>
Then, when I run it (just doing a mock up post to google), I can see the password is correctly encrypted to sha512:

I can verify this using\u00a0https:\/\/caligatio.github.io\/jsSHA\/<\/a>\u00a0and plugging in my password (abcxyz123).\u00a0 It's the same number (starts with 24bf9c...):

HTH,<\/p>","className":"post__content__best_answer"}">