对响应值使用Jmeter加密时出错

fcg9iug3  于 2022-11-09  发布在  其他
关注(0)|答案(1)|浏览(193)

我目前正在使用RSA加密来加密敏感数据的应用程序中工作。我曾尝试合并标准加密方法,但它引发了错误。有人能告诉我我是否做对了吗?
下面是我用来加密值的代码(string2Encrypt)

import javax.crypto.Cipher
import java.security.KeyFactory
import java.security.spec.X509EncodedKeySpec

def publicKey = '5dy47yt7ty5ad283c0c4955f53csa24wse244wfrfafa34239rsgd89gfsg8342r93r98efae89fdf9983r9gjsdgnsgjkwt23r923r2r0943tf9sdg9d8gfsgf90sgsf89grw098tg09s90ig90g90s903r5244r517823rea8f8werf9842tf24tf42e0132saf9fg6f65afa43f12r103tf4040ryrw0e9rtqtwe0r9t04ty8842t03e9asfads0fgadg675'

def x509PublicKey = new X509EncodedKeySpec(publicKey.decodeBase64())
def keyFactory = KeyFactory.getInstance('RSA')
defFactory.generatePublicc(x509PublicKey)
def string2Encrypt = '("testinga@gmail.com|testingb@gmail.com").'
def encryptCipher = Cipher.getInstance('RSA')encryptCipher.init(Cipher.ENCRYPT_MODE key)
def secretMessage = string2Encrypt.getBytes('UTF-8')
def encryptedMessage = encryptCipher.doFinal(secretMessage)

def encodedMessage = encryptedMessage.encodedBase64().toString()
vars.put('encodedMessage',encodedMessage)

我遇到的错误

javax.script.scriptException: groovy.lang.MissingPropertException: No Such Property: `defFactory for class: Script21`

传递的参数加密后,我希望看到的输出

"ParameterEmailDetails":"428f8wefg87hg8s74tr52493r5219r0921tf09gv09sg0958t347tr1348r8feqacadvf98bnvncsaopdpwoq8r3r234r89r024rtf90eopfgsodg9503y68yhhi898jngdhhs9hg538hfhlhko539gh35l35s09fhbs09ns9htwj986jh3509h3250bsf90hsf9nsf0h9sf9h0"

请在这方面给予帮助。

8cdiaqws

8cdiaqws1#

您在尝试从某个源代码复制粘贴代码时出错,显示的不是有效的Groovy代码,因此解释/编译失败
这一行:

defFactory.generatePublicc(x509PublicKey)

应该看起来像

def key = keyFactory.generatePublic(x509PublicKey)

还有这一行:

def encryptCipher = Cipher.getInstance('RSA')encryptCipher.init(Cipher.ENCRYPT_MODE key)

应分为2行:

def encryptCipher = Cipher.getInstance('RSA')
encryptCipher.init(Cipher.ENCRYPT_MODE, key)

或在语句之间放置分号:

def encryptCipher = Cipher.getInstance('RSA');encryptCipher.init(Cipher.ENCRYPT_MODE key)

更多信息:

相关问题