The bitcoin wiki says this:
How to create Bitcoin Address
0 - Having a private ECDSA key
18E14A7B6A307F426A94F8114701E7C8E774E7F9A47E2C2035DB29A206321725
1 - Take the corresponding public key generated with it 0450863AD64A87AE8A2FE83C1AF1A8403CB53F53E486D8511DAD8A04887E5B23522CD470243453A299FA9E77237716103ABC11A1DF38855ED6F2EE187E9C582BA6
2 - Perform SHA-256 hashing on the public key
600FFE422B4E00731A59557A5CCA46CC183944191006324A447BDB2D98D4B408
but when I run a sha256 on 0450863AD64A87AE8A2FE83C1AF1A8403CB53F53E486D8511DAD8A04887E5B23522CD470243453A299FA9E77237716103ABC11A1DF38855ED6F2EE187E9C582BA6
I don't get
600FFE422B4E00731A59557A5CCA46CC183944191006324A447BDB2D98D4B408
What I get is
32511e82d56dcea68eb774094e25bab0f8bdd9bc1eca1ceeda38c7a43aceddce
what am I doing wrong?
Convert the hex string back to bytes and sha256 the bytes.
Something like that:
>>> hex_string = ('0450863AD64A87AE8A2FE83C1AF1A8403CB53F53E486D8511DAD8A04887E5B23522CD470243453A299FA9E77237716103ABC11A1DF38855ED6F2EE187E9C582BA6')
>>> hex_data = hex_string.decode('hex')
>>> hashlib.sha256(hex_data).hexdigest()
'600ffe422b4e00731a59557a5cca46cc183944191006324a447bdb2d98d4b408'
Related
I am trying to use the python code given + test vector 2 given by rfc
https://www.rfc-editor.org/rfc/rfc8032#section-7.1
expected results
secret_to_public()
SecretKey = 4ccd089b28ff96da9db6c346ec114e0f
PublicKey = 3d4017c3e843895a92b70aa74d1b7ebc
my result
secret_to_public()
SecretKey = 4ccd089b28ff96da9db6c346ec114e0f
PublicKey = 4e15...56d7
my concerns
Am I using the right secret key ?
They seem to show a 64 byte secret key but ed25519 uses a 32 byte secret key.
Am I encoding the secret key / decoding the result correctly ?
code
#https://www.rfc-editor.org/rfc/rfc8032#section-7.1
sK = b"4ccd089b28ff96da9db6c346ec114e0f"
print(sK)
print(len(sK))
for i in range(32):
print(hex(secret_to_public(sK)[i]))
Python Gist :
https://gist.github.com/redazul/668ca5d8501e73509a55777f5c84e469
Taken from https://www.rfc-editor.org/rfc/rfc8032#section-6
Thanks #Topaco
#https://www.rfc-editor.org/rfc/rfc8032#section-7.1
sK=bytes.fromhex("4ccd089b28ff96da9db6c346ec114e0f5b8a319f35aba624da8cf6ed4fb8a6fb")
print(sK)
print(len(sK))
for i in range(32):
print(hex(secret_to_public(sK)[i]))
I am trying to convert my private key to uint8Array format. But I am getting "bad secret key size" error. Why? Here is my code:
const secretKey = bs58.decode("BxAN...RGM"); // secretKey: Uint8Array(32)
console.log(Web3.Keypair.fromSecretKey(secretKey));
It is a devnet phantom wallet address. I tried with different keys, but it still does not work.
I was incorrectly passing the public key as an argument instead of private key. The correct syntax is:
Web3.Keypair.fromSecretKey(secretKey);
Which caused Error: bad secret key size. You should pass the private key(in uint8Array format), not the public key.
from jose import jws
from jose import jwe
with open('privkey.pem', mode='r') as privatefile:
privkey = privatefile.read()
with open('pubkey.pem', mode='r') as pubfile:
pubkey = pubfile.read()
####################################
## Signing request with private key
####################################
query = {
"QueryType": 1,
"QuerySubType": None
}
signed = jws.sign(query, privkey, algorithm='RS256')
print(signed)
# verify = jws.verify(signed, pubkey, algorithms=['RS256'])
# print(verify)
################################
## Encryption
################
encrypted = jwe.encrypt(signed, pubkey, algorithm='RSA_OAEP', encryption='A256CBC_HS512')
print(encrypted)
I created rsa key pair of size 2048.
The singing and verification works fine.
I am getting en error "jose.exceptions.JWEError: Algorithm RSA_OAEP not supported". I've tried all the algorithms and encryption, but getting the same error for algorithms not supported for all of them.
What am I doing wrong here?
The key management and the content encryption algorithms are specified wrongly. Use hyphens instead of underscores:
encrypted = jwe.encrypt(signed, pubkey, algorithm='RSA-OAEP', encryption='A256CBC-HS512')
However, it is more robust to apply the provided constants defined in the class jose.constants.Algorithms:
from jose.constants import Algorithms
...
encrypted = jwe.encrypt(signed, pubkey, algorithm=Algorithms.RSA_OAEP, encryption=Algorithms.A256CBC_HS512)
I am following the below steps to compute the HMAC using SHA1 algorithm using two different API and both the outputs are not matching.
1) I first compute HMAC for a given data and key using SHA1 algorithm through BouncyCastle API.
2) We compute HMAC for the data and key inside the HSM(Thales) using PKCS11 API(Pkcs11Interop).
When we compared the results of 1 and 2 the data does not match.
Bouncy Castle code:
HMAC hmac = HMACSHA1.Create();
String key = "BC55B4580589775F887890A7ACA5E624";
hmac.Key = Util.HexStringToByteArray(key);
byte[] modInput = Util.HexStringToByteArray("000000000000000000000006000080012b0601040181e438010102041603");
String ki = Util.ByteArrayToHexString(hmac.ComputeHash(modInput));
PKCS11 code:
ObjectHandle k = FindObjectByLabel(keyLabel);//same key as above
Mechanism m = new Mechanism(CKM.CKM_SHA_1_HMAC);
**//We have verified that both key and data value are the same**
return mSession.Connection.Sign(m, k, data);
Can anyone please help on this?
I am trying to implement DHE_DSS into go's crypto/tls package. Unfortunately I can not seem to get the PreMasterSecret (Z) to be the same, my basic workflow is:
Receive Server Key Exchange Message
Extract P, G, Ys
Verify using the digital signature provided
Prepare Client Key Exchange Message
Create client's Xc
Generate Yc (Yc = G^Xc % P)
Generate Z (Z = Ys^Xc % P)
Send back Yc, packed like so:
ckx := make([]byte, len(yC)+2)
ckx[0] = byte(len(Yc)>>8)
ckx[1] = byte(len(Yc))
copy(ckx[2:], yBytes)
However, when I am debugging this with gnutls-serv the two PreMasterSecrets (Z) are different. Do I need to sign the returned Yc, or perhaps pack it in another way? I can not see anything in RFC 5246 to suggest this.
<-- EDIT -->
Here is a patch of my changes:
https://08766345559465695203.googlegroups.com/attach/48587532c74b4348/crypto.patch?part=4&view=1&vt=ANaJVrHbwydqEZc3zjUWqQ5C8Q5zEkWXZLdL0w6JJG3HYntOlBurUTY7mc9xR9OTfE0bJxs4eeL5a5SGd2jj9eIfXcwJQgLvJchXOgkYKBBynbPfshY8kuQ
Client key exchange will contain:
length (2 bytes) --> Y_C (in plain text)
I have implemented TLS in Java and I follow the same structure and works fine for me.
Do I need to sign the returned Yc?
No there is no need to sign the client DH public value, it is transferred in plain text.
You can take a pcap and check whether same values are being transferred in the packet. Also if GNU TLS has logger for printing the Y_C received, then you can check if proper data is being received.
If in case you still getting different Pre-Master secret then there seems to be some issue with the logic of generation of secret.