jmeter-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Markus Obermann <markus.oberm...@yahoo.de.INVALID>
Subject BeanShell Sampler error: Typed variable declaration: Method Invocation KeyFactory.getInstance
Date Fri, 13 Sep 2019 11:27:27 GMT
Hey all,
im using JMeter 5.0 with JRE 9.0.2.
I have a ECDSA Private Key on my disk and want to sign some file on my disk too.My priv. key
looks like this: 
-----BEGIN EC PARAMETERS-----
BgUrgQQACg==
-----END EC PARAMETERS-----
-----BEGIN EC PRIVATE KEY-----
MHQCAQEEIDzESrZFmTaOozu2NyiS8LMZGqkHfpSOoI/qA9Lw+d4NoAcGBSuBBAAK
oUQDQgAE7kIqoSQzC/UUXdFdQ9Xvu1Lri7pFfd7xDbQWhSqHaDtj+XY36Z1Cznun
GDxlA0AavdVDuoGXxNQPIed3FxPE3Q==
-----END EC PRIVATE KEY-----
note:this is of course not a real key. its just what my file looks like if i view it with
vi.

I found this lil code snippet.
File privkeyfile = new File(path_to_privkey_file);File datafile = new File(path_to_datafile);
FileInputStream fis = new FileInputStream(f);
DataInputStream dis = new DataInputStream(fis);
byte[] keyBytes = new byte[(int) privkeyfile.length()];
dis.readFully(keyBytes);
dis.close();
PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(keyBytes);
KeyFactory kf = KeyFactory.getInstance("ECDSA");PrivateKey privateKey = factory.generatePrivate(spec);
Well the next step would be to sign my file with my private key and then encode it base64.
I though of doing it like this:

Signature ecdsaSign = Signature.getInstance("SHA256withECDSA");
ecdsaSign.initSign(privateKey);
ecdsaSign.update(plaintext.getBytes("UTF-8"));
byte[] signature = ecdsaSign.sign();
String pub = Base64.getEncoder().encodeToString(publicKey.getEncoded());
String sig = Base64.getEncoder().encodeToString(signature);

But in BeanShell i will get the Error: "Typed variable declaration: Method Invocation KeyFactory.getInstance"
Any ideas?

P.S.
ofc i do have imported the java.security.KeyFactory; and PKCS8EncodedKeySpec.




Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message