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.