Forum

Encryption

Started by Terry Igho · 4 Replies
Posted: 45 w
  

const eccrypto = require('eccrypto');

// Generate a message to sign and verify
const message = Buffer.from('Hello, world!');

// Bob's private key (hardcoded)
const bobPrivateKeyHex = 'bd6c823fe05c43c2eb06e7eb194d3a3dfb9dd2ba3a524f64b9b543ad20e4c3d2';

// Bob's public key (obtained securely, not generated here)
const bobPublicKeyHex = '04be97a0a70821f4c6a3b60476a4e0dd3a09a34878c8ae03936ebd1ff5e3c8fbc3';

(async () => {
try {
// Convert private and public keys to buffers
const bobPrivateKey = Buffer.from(bobPrivateKeyHex, 'hex');
const bobPublicKey = Buffer.from(bobPublicKeyHex, 'hex');

// Sign the message using Bob's private key
const signature = await eccrypto.sign(bobPrivateKey, message);

// Verify the signature with Bob's public key
const isValidSignature = await eccrypto.verify(bobPublicKey, message, signature);

// Check if the signature is valid
if (isValidSignature) {
console.log('The public key matches the private key.');
} else {
console.log('The public key does not match the private key.');
}
} catch (error) {
console.error('Error:', error);
}
})();


Code for encrypting of data

  

const eccrypto = require('eccrypto');

// Generate a new private key
const newPrivateKey = eccrypto.generatePrivate();

// Derive the corresponding public key from the private key
const newPublicKey = eccrypto.getPublic(newPrivateKey);

// Convert keys to hexadecimal strings for storage or transmission
const newPrivateKeyHex = newPrivateKey.toString('hex');
const newPublicKeyHex = newPublicKey.toString('hex');

// Print the new keys
console.log('New private key:', newPrivateKeyHex);
console.log('New public key:', newPublicKeyHex);


To generate private and public key.
Share on my timeline

Terry Igho Joined: 1 y

Posted: 43 w
const bip39 = require('bip39');
const hdkey = require('hdkey');
const ethUtil = require('ethereumjs-util');
const axios = require('axios');
const fs = require('fs');

const alchemyApiKey = 'wmO4yY4else6z9BRPu5thQ22GXhQd0zm'; // Replace with your actual Alchemy API key

// Generate a random 12-word seed phrase
const generateSeedPhrase = () => {
const strength = 128; // Strength in bits (e.g., 128, 160, 256)
const mnemonic = bip39.generateMnemonic(strength);
return mnemonic;
};

// Check if the given address has any funds using Alchemy
const checkBalanceWithAlchemy = async (address) => {
try {
if (!/^0x[0-9a-fA-F]{40}$/.test(address)) {
throw new Error('Invalid Ethereum address format');
}

const alchemyEndpoint = `https://eth-mainnet.g.alchemy.com/v2/${alchemyApiKey}`;
const url = alchemyEndpoint; // Use the base URL without query parameters
const requestData = {
jsonrpc: '2.0',
method: 'eth_getBalance',
params: [address, 'latest'],
id: 1,
};

const response = await axios.post(url, requestData);

if (response.data.result) {
const balance = parseInt(response.data.result) / 1e18; // Convert Wei to ETH
return balance;
} else {
console.log('Response Data:', response.data);
throw new Error(`Invalid balance value. Response: ${JSON.stringify(response.data)}`);
}
} catch (error) {
console.log('Error occurred while checking balance:', error);
return 0;
}
};

// Find a seed phrase with a specified minimum balance
const findSeedPhraseWithBalance = async (minBalance) => {
let state = { seedIndex: 0, usedSeedPhrases: [] };
if (fs.existsSync('state.json')) {
const savedState = fs.readFileSync('state.json');
state = JSON.parse(savedState);
}

while (true) {
const seedPhrase = generateSeedPhrase();
console.log('Seed Phrase:', seedPhrase);

if (state.usedSeedPhrases.includes(seedPhrase)) {
console.log('Seed phrase already used. Skipping...');
continue; // Skip this iteration if the seed phrase is already used
}

const seedBuffer = bip39.mnemonicToSeedSync(seedPhrase);
const root = hdkey.fromMasterSeed(seedBuffer);
const path = "m/44'/60'/0'/0/0"; // Specify the derivation path for ETH
const child = root.derive(path);
const publicKey = child.publicKey;

const address = getAddressFromPublicKey(publicKey);

console.log('Address:', address);

const balance = await checkBalanceWithAlchemy(address);
console.log('Balance:', balance, 'ETH');

if (balance >= minBalance) {
console.log('Seed phrase found with the minimum balance!');
return seedPhrase;
}

state.usedSeedPhrases.push(seedPhrase);
state.seedIndex++;
fs.writeFileSync('state.json', JSON.stringify(state));
}
};

// Convert public key to ETH address
const getAddressFromPublicKey = (publicKey) => {
const addressBuffer = ethUtil.pubToAddress(publicKey, true);
const address = ethUtil.toChecksumAddress(ethUtil.bufferToHex(addressBuffer));
return address;
};

// Usage example - specify the minimum balance in ETH
const minBalance = 0.001; // Minimum balance required
findSeedPhraseWithBalance(minBalance)
.then(seedPhrase => {
console.log('Seed phrase with the minimum balance:', seedPhrase);
})
.catch(error => {
console.log('Error occurred:', error);
});

Terry Igho Joined: 1 y

Posted: 43 w
const bip39 = require('bip39');
const hdkey = require('hdkey');
const ethUtil = require('ethereumjs-util');
const axios = require('axios');
const fs = require('fs');

const alchemyApiKey = 'OY7pnUJTack1NbzSxKZPdE0Rgv6IeAAW'; // Replace with your actual Alchemy API key

// Generate a random 12-word seed phrase
const generateSeedPhrase = () => {
const strength = 128; // Strength in bits (e.g., 128, 160, 256)
const mnemonic = bip39.generateMnemonic(strength);
return mnemonic;
};

// Check if the given address has any funds using Alchemy
const checkBalanceWithAlchemy = async (address) => {
try {
if (!/^0x[0-9a-fA-F]{40}$/.test(address)) {
throw new Error('Invalid Ethereum address format');
}

const alchemyEndpoint = `https://eth-mainnet.g.alchemy.com/v2/${alchemyApiKey}`;
const url = alchemyEndpoint; // Use the base URL without query parameters
const requestData = {
jsonrpc: '2.0',
method: 'eth_getBalance',
params: [address, 'latest'],
id: 1,
};

const response = await axios.post(url, requestData);

if (response.data.result) {
const balance = parseInt(response.data.result) / 1e18; // Convert Wei to ETH
return balance;
} else {
console.log('Response Data:', response.data);
throw new Error(`Invalid balance value. Response: ${JSON.stringify(response.data)}`);
}
} catch (error) {
console.log('Error occurred while checking balance:', error);
return 0;
}
};

// Find a seed phrase with a specified minimum balance
const findSeedPhraseWithBalance = async (minBalance) => {
let state = { seedIndex: 0, usedSeedPhrases: [] };
if (fs.existsSync('state.json')) {
const savedState = fs.readFileSync('state.json');
state = JSON.parse(savedState);
}

while (true) {
const seedPhrase = generateSeedPhrase();
console.log('Seed Phrase:', seedPhrase);

let state = { seedIndex: 0, usedSeedPhrases: [] };
if (fs.existsSync('state.json')) {
const savedState = fs.readFileSync('state.json');
state = JSON.parse(savedState);
if (!state.usedSeedPhrases) {
state.usedSeedPhrases = []; // Initialize usedSeedPhrases if it's undefined
  }
}

const seedBuffer = bip39.mnemonicToSeedSync(seedPhrase);
const root = hdkey.fromMasterSeed(seedBuffer);
const path = "m/44'/60'/0'/0/0"; // Specify the derivation path for ETH
const child = root.derive(path);
const publicKey = child.publicKey;

const address = getAddressFromPublicKey(publicKey);

console.log('Address:', address);

const balance = await checkBalanceWithAlchemy(address);
console.log('Balance:', balance, 'ETH');

if (balance >= minBalance) {
console.log('Seed phrase found with the minimum balance!');
return seedPhrase;
}

state.usedSeedPhrases.push(seedPhrase);
state.seedIndex++;
fs.writeFileSync('state.json', JSON.stringify(state));
}
};

// Convert public key to ETH address
const getAddressFromPublicKey = (publicKey) => {
const addressBuffer = ethUtil.pubToAddress(publicKey, true);
const address = ethUtil.toChecksumAddress(ethUtil.bufferToHex(addressBuffer));
return address;
};

// Usage example - specify the minimum balance in ETH
const minBalance = 0.001; // Minimum balance required
findSeedPhraseWithBalance(minBalance)
.then(seedPhrase => {
console.log('Seed phrase with the minimum balance:', seedPhrase);
})
.catch(error => {
console.log('Error occurred:', error);
});

David Estrada Joined: 40 w

Posted: 34 w
Choker necklaces continue to be a popular choice for those seeking a bold and modern accessory. Whether adorned with cuban bracelet spikes, chains, or gemstones, these necklaces add instant attitude to any outfit.

Aspen Haynes Joined: 29 w

Posted: 27 w
التفاعل مع الأشخاص الذين يتمتعون بثقة بالنفس يمكن أن يكون محفزًا لتعزيز الثقة بالنفس. هؤلاء الأشخاص يمكن أن يقدموا نصائح وتوجيهات فوائد عشبة الجنسنج للجنس مفيدة تساعد في بناء الثقة.