0

How do I hide specifically "private_key" from being viewed by everyone as everything is getting stored on the array publically including private_key?

I want to display all the data like address,user Id,first name,last name to be viewed by everyone on the blockchain except for the private_key.

struct User {

 address wallet_address; string userId; string first_name; string last_name; string email_id; bool set; string private_key; } mapping(address => User) users; mapping(string => address) walletAccount; mapping(address => uint) public balanceOf; User[] public registeredArray; 

function createNewUser(address userAcc,string memory _id,string memory firstName,string memory lastName,string memory emailId,string memory _private_key) public {

User storage user = users[userAcc];

users[userAcc] = User(userAcc,_id,firstName,lastName,emailId,true,_private_key);

walletAccount[emailId] = userAcc;

registeredArray.push (users[userAcc]);

}

function getAllUsers()public view returns(User[] memory){

return registeredArray;

}

1 Answer 1

1

Everything that is submitted to the blockchain is publicly accessible, even "private" state variables. So it would not be possible to store private key in blockchain and keep it secret.

If storing private key on-chain is absolutely necessary, you may consider first encrypting private key and only store the encrypted data on blockchain. Then have your decryption algorithm secret and off-chain to get back the stored private key on your back-end.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.