1

I have a private key in the following format,

-----BEGIN PRIVATE KEY----- MIIJQgIBADANBgkqhkiG9w0BAQEFAASCCSwwggkoAgEAAoICAQCp1cSazYun0pCX . . T0r1PTCefoaLDO7gvwJ1Aa6rmF8SrA== -----END PRIVATE KEY----- 

I am trying to use this key to create a testnet client,

const operatorIdStr = await getAddress(); const operatorKeyStr = readFileSync(SECRET_KEY_PATH, "utf8"); const operatorId = AccountId.fromString(operatorIdStr); const operatorKey = await PrivateKey.fromPem(operatorKeyStr); client = await Client.forTestnet().setOperator(operatorId, operatorKey); 

I am getting following error message, BadKeyError: invalid private key length: 2358 bytes

Please note that I am trying to integrate with Fireblocks and private key is generated by Fireblocks at the time of wallet creation. Using openssl command the key length I see is Private-Key: (4096 bit, 2 primes)

Is this the right approach? Is there a sample code available to use a RSA key?

I tried converting the key to DER format using openssl, and tested with PrivateKey.fromStringDerPem(operatorKeyStr) but that did not help.

2

1 Answer 1

0

Hello i think you are missing something, in the hedera dashboard on the testnet network you have 5 different addresses... one of them is "DER Encoded Private Key" you should copy this as private key (operatorKey) and operatorID should be Account ID. to attach them on your testnet network do as following:

 //import .env credentials on your file.(becareful it should be on root of the working file) import dotenv from "dotenv"; dotenv.config(); // Load your testnet account from environment variables const myAccountId = process.env.MY_ACCOUNT_ID; const myPrivateKey = process.env.MY_PRIVATE_KEY; // Create a Hedera client connected to testnet. no need to use await for this const client = Client.forTestnet(); client.setOperator(myAccountId, myPrivateKey); async function createTopic() { //your topic... } createTopic(); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.