Post
Share your knowledge.
How do I extract the Base64 from a .key file?
I'm a beginner and I'm trying to get the Base64 encoding from a .key file generated using sui keytool generate
. Could someone guide me on how to confirm that the file content is indeed Base64 encoded and how to extract it if necessary?
- Sui
- SDKs and Developer Tools
Answers
4When you use the sui keytool generate command, the output is indeed in a Base64 format. The .key file generated contains Base64 encoded information, including the keypair. You typically don't need to extract Base64 from it separately unless you have specific needs for the Base64 string itself.
A .key file usually stores your private key in raw bytes or hex format, not Base64. To convert it to Base64 (or extract Base64 if already encoded), you first need to inspect its format: • If it’s hex‑encoded (common for Sui keys): Convert hex → raw bytes → Base64. • If it’s already Base64 (starts with MIIB… or has = padding): You can use it directly without conversion. • If it’s raw binary: Encode the bytes directly to Base64.
Example using Node.js:
const fs = require('fs');
// Read .key file const keyData = fs.readFileSync('mykey.key', 'utf8').trim();
// If hex → convert to Base64 const base64Key = Buffer.from(keyData, 'hex').toString('base64'); console.log(base64Key);
Example using Python:
import base64
with open('mykey.key', 'r') as f: hex_data = f.read().strip()
base64_key = base64.b64encode(bytes.fromhex(hex_data)).decode() print(base64_key)
Once you have the Base64 string, you can import it into tools or SDKs that require Base64 keys (e.g., for Sui wallet operations).
If your key file was created using a tool like sui keytool
, the entire content should be Base64 encoded. However, if you want to confirm or use it as a Base64 string elsewhere, you can read the file content as you would any text file, as it's already in a Base64 formatted string.
When you use the sui keytool generate
command, the output is indeed in a Base64 format. The .key file generated contains Base64 encoded information, including the keypair. You typically don't need to extract Base64 from it separately unless you have specific needs for the Base64 string itself.
Do you know the answer?
Please log in and share it.
Sui is a Layer 1 protocol blockchain designed as the first internet-scale programmable blockchain platform.
- Why does BCS require exact field order for deserialization when Move structs have named fields?65
- How to Maximize Profit Holding SUI: Sui Staking vs Liquid Staking514
- Multiple Source Verification Errors" in Sui Move Module Publications - Automated Error Resolution55
- Sui Move Error - Unable to process transaction No valid gas coins found for the transaction419
- Sui Transaction Failing: Objects Reserved for Another Transaction49