How can I find user public address from his private key ?
Already I found a way to convert public to hex Address also private to hex and reverse
but get stuck in this one !
Using TronWeb, you can call this function:
const address = tronWeb.address.fromPrivateKey(newAccount.privateKey);
That code comes from one of TronWeb's tests
for bitcoin you need use this package to find public key => dart_wif
print('hex :::::: ${HEX.encode(index.privateKey!)}');
WIF decoded = WIF(version: 128, privateKey: index.privateKey!, compressed: true);
String key = wif.encode(decoded);
print(key);
If you are using python, the official tronpy document doesn't mentioned this. However, you can find the answer by yourself.
Open ipython from terminal, create a key object from a random key, input the key variable name and press tab twice, you will see all the attributes and functions of the object.
import tronpy
my_random_key = tronpy.keys.PrivateKey.random()
my_key = tronpy.keys.PrivateKey.fromhex(my_random_key)
my_key.public_key.to_base58check_address()
Related
After goin through an article on how to use node-rsa Public and Private keys for encrypting/decrypting data, although I was able to successfully follow the implementation.
But, there was a dilema regarding how to manage the Private key which is used for decryption.
Most online suggestions mentioned that we should not push Private key to GitHub repos.
How do I add this Private key as a GitHub secret or Environment variable, so that I can use it inside GitHub Actions CI?
Even if I try to use Environment variable in GitHub, I can only specify a key value pair.
But my Private key looks something like this:
const NodeRSA = require('node-rsa')
const key = new NodeRSA()
const privatePem = '---BEGIN RSA PRIVATE KEY---abcD...vbGa---END RSA PRIVATE KEY---'
key.importKey(privatePem, 'pkcs1-pem')
I use the Private key to decrypt data in the following way:
const encryptedData = "abAxksl8jl..."
const decryptedData = key.decrypt(encryptedData, 'utf8')
console.log(decryptedData)
Any help or suggestion would be highly appreciated. Thanks!
I have a requirement where I need to do Encryption of my Private Key using Public Key(provided by third party) with RSA/ECB/PKCS1 Encryption
The Public Key is already Padded.
I am generating the private key using cl_sec_sxml_writer=>generate_key( cl_sec_sxml_writer=>co_aes256_algorithm_pem ). Is this the correct way to generate a new key or we can have any random string as a private key?
This private key will be used to encrypt a data string using AES/ECB/PKCS7 padding encryption and then convert to BASE64 and send it via API call. For AES/ECB/PKCS7 padding, I am using the classes provided by following https://github.com/Sumu-Ning/AES. pfb implementation below:
CALL METHOD zcl_aes_utility=>encrypt_xstring
EXPORTING
i_key = lv_xstr
i_data = lv_pwd_xstr
* i_initialization_vector =
i_padding_standard = zcl_byte_padding_utility=>MC_PADDING_STANDARD_PKCS_7
i_encryption_mode = zcl_aes_utility=>mc_encryption_mode_ecb
IMPORTING
e_data = lv_encrypt
My query is , how do I encrypt the private key using public key and RSA/ECB/PKCS1 Encryption.
The public key is of length 399 chars and something like this
DfP4hVgyXMSNWJFWakwo44p1PMyRKSmFG+UGq
I have checked other blogs that asks to use standard fm SSF_KRN_ENVELOPE but I am not able to understand how to use it.
Please help. Let me know in case of any further details required.
I need to pass a UniqueIdentifier as a string between two services. Unfortunately UniqueIdentifier#toString and UniqueIdentifier.fromString do not work well if an externalId is set.
What is the canonical way of serializing and deserializing a UniqueIdentifier?
If you're using Corda's library to create a UniqueIdentifier set with a custom external id, you can see that the toString() will generate a pattern of ${externalId}_$id i.e dummyExternalId_10ed0cc3-7bdf-4000-b610-595e36667d7d.
So to covert it back to UniqueIdentifier from that string, just split by delimiter of _
if (p.text.contains("_")) {
val ids = p.text.split("_")
//Create UUID object from string.
val uuid: UUID = UUID.fromString(ids[1])
//Create UniqueIdentifier object using externalId and UUID.
return UniqueIdentifier(ids[0], uuid)
}
Link here
If you have underscore in external id, you'll probably need your own function.
val potentialIds = input.split("_")
// Drop last one and stitch back the external id
val externalIdString = potentialIds.dropLast(1).joinToString("_")
// Last one is the UUID
val uuid = UUID.fromString(potentialIds.last())
val finalUniqueIdentifier = UniqueIdentifier(externalIdString, uuid)
Wait a sec, do you have to create an UniqueIdentifier for some business of yours? In that case you can just create a UniqueIdentifier from scratch and pass it as a variable between services (transactions accept external attachment).
If you have to "extract" the uniqueIdentifier of your State I don't think that is possible.
If I missed the point I apologize in advance :D
I might be confused about something, but when I store a custom object from the Java Riak client and then try to read that object using the Python Riak client, I end up with a raw json string instead of a dict.
However, if I store a the object in python, I am able to output a python dictionary when fetching that object.
I could simply use a json library on the python side to resolve this, but the very fact that I am experiencing this discrepancy makes me think that I am doing something wrong.
On the Java side, this is my object:
class DocObject
{
public String status; // FEEDING | PERSISTED | FAILED | DELETING
public List<String> messages = new ArrayList<String>();
}
class PdfObject extends DocObject
{
public String url;
public String base_url;
}
This is how I am storing that object in Riak:
public void feeding(IDocument doc) throws RiakRetryFailedException {
PdfObject pdfObject = new PdfObject();
pdfObject.url = doc.getElement("url").getValue().toString();
pdfObject.base_url = doc.getElement("base_url").getValue().toString();
pdfObject.status = "FEEDING";
String key = hash(pdfObject.url);
pdfBucket.store(key, pdfObject).execute();
}
And this is what I am doing in Python to fetch the data:
# Connect to Riak.
client = riak.RiakClient()
# Choose the bucket to store data in.
bucket = client.bucket('pdfBucket')
doc = bucket.get('7909aa2f84c9e0fded7d1c7bb2526f54')
doc_data = doc.get_data()
print type(doc_data)
The result of the above python is:
<type 'str'>
I am expecting that to be <type 'dict'>, just like how the example here works:
http://basho.github.com/riak-python-client/tutorial.html#getting-single-values-out
I am perplexed as to why when the object is stored from Java it is stored as a JSON string and not as an object.
I would appreciate if anybody could point out an issue with my approach that might be causing this discrepancy.
Thanks!
It would appear you've found a bug in our Python client with the HTTP protocol/transport.
Both the version you're using and the current one in master are not decoding JSON properly. Myself and another dev looked into this this morning and it appears to stem from an issue with charset parameter being returned from Riak with the content-type as Christian noted in his comment ("application/json; charset=UTF-8")
We've opened an issue on github (https://github.com/basho/riak-python-client/issues/227) and will get this corrected.
In the mean time the only suggestion I have is to decode the returned JSON string yourself, or using the 1.5.2 client (latest stable from pypy) and the Protocol Buffers transport:
client = riak.RiakClient(port=8087, transport_class=riak.RiakPbcTransport)
it will return the decoded JSON as a dict as you're expecting.
I am trying to wrap a generated symmetric key using the public key which i want to extract it from the Public Certificate(.der / .cer ) when i am passing the public key for wrapping the symmetric key i am getting an "java.security.InvalidKeyException" exception "Only keys that exist in 'RAW' format are supported"
When i am loading the public certificate using file input stream as
publicCertificate = new X509Certificate(new FileInputStream("src/resources/mydomain.com.der"));
for extracting the publicKey i am using this getPublicKey(); method
publicKey = publicCertificate.getPublicKey();
I am such exception when i extracted the public key and it is in the X.509 format which i need to convert it into RAW format.
Can anyone please help me out here.
Thanks in Advance.