Error: bad secret key size while converting base58 secret key to uint8Array format - solidity

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.

Related

That hash, timestamp and key combination is invalid

note. (there are quite a few questions with this same problem but none worked for me.)
using this tool. https://www.md5.cz/
Adding the value of 1 to the timestamp then the private API and finally the public. API generates the hash, and pasting it followed by the public API key generates this error.
{
"code": "InvalidCredentials",
"message": "That hash, timestamp and key combination is invalid."
}
here the url: https://gateway.marvel.com/v1/public/characters?ts=5&apikey="publicapi"&hash="hash"

I am trying to understand what exactly is signature query parameter in binance

I am trying to access this endpoint, where signature parameter has to be sent as query parameter
https://binance-docs.github.io/apidocs/spot/en/#current-open-orders-user_data
I am trying to understand what value for that signature key should be passed.
Firstly i thought it was secret key binance exchange given. But it was not, because when try to above endpoint it says that :
{
"code": -1022,
"msg": "Signature for this request is not valid."
}
^Postman
As you can see i passed my secret key as the value for signature key. It is not working. So what am i really missing here ? or do i need to do some transformations to the secret key ? please help me understand it and advance thanks!
It looks like you are putting the timestamp before the recvWindow in your query string.
timestamp is always the last parameter and the order of the parameters in the docs clearly puts recvWindow before timestamp.
I managed to get it working with query string recvWindow=60000&timestamp=1652512756366
Secret key and signature are two different things.
You need to sign the parameters with your secret key. This process produces a signature. And then you pass this resulting signature to the payload.
I'm not sure how to produce the signature in C++, however Binance docs show an example of signing the data in console with openssl (scroll right on all 3 examples).

Padding mode not valid when try do decrypt a JWE payload with RSA-OAEP-256 and A256GCM

I have no expertise with cryptography, i'm trying to decrypt a JWE payload in ASP.net core C#, the information that i have is the encryption was performed with RSA-OAEP-256 and A256GCM, so i'm using Jose libraries do deal with c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0slWMQywIhqZ7dbyyWv_S-oxecVneZ4LlSW-hxCYJGtrsGJtnEaRHVYZJ-N-MjwBm9nJU4P8mY9Nz9MPbWbovb8gJ5DLXFppZjReRk2A2zHTGKzav6Q0DYKI0NGmSDHJW6UbSjVzBBJe2r85NS4u5HGS_wyEhXXnMtJZdn6VBQj9AEY4Jrt2xZzCRoqWlUI46uMObvWq5qvkKCPcSLKyrHEIigbR3JmW3zzDNvc39RmiC6cbJ0Ypb-G0D4CNwdV2bemLzs29NIWms75cqMHxlkyKOqEX5UsYlGBhra_kM.vykYzq6TQ8ApQdyREGo6-g
var jwtSettings = new JwtSettings();
jwtSettings.RegisterMapper(new JwtPayloadConverter.JsonMapperJwt());
var decodedJwt = Jose.JWT.Decode(paylaodRetornoStone2, rsa, Jose.JweAlgorithm.RSA_OAEP_256, Jose.JweEncryption.A256GCM, jwtSettings);
when i try do decrypt the payload, i'm getting this error: specified padding mode is not valid for this algorithm.
the specific part of code that is throwing this exception is the:
byte[] cek = keyManagement.Unwrap(encryptedCek, key, jweAlgorithm.KeySize, header);
the implementation of RsaOaep256KeyManagement is doing this:
return Ensure.Type<RSA>(key, "RsaKeyManagement algorithm expects key to be of RSA type.").Decrypt(encryptedCek, RSAEncryptionPadding.OaepSHA256);
it seens that paddind mode is right, anyone have an idea to how fix this error?

Why an HSM generated key component has parity error?

Using Thales HSM, the following commands were executed:
Generate 2 ZMK components using A2 command:
A20002U;[print fields]
Components are successfully generated and printed, in A3 response we have the encrypted component:
A300[component][CV]
Form a key from encrypted components:
A42000U[1st component][2nd component]
Key is successfully formed:
A500[key][CV]
Calculate check value of encrypted component:
BUFF1[1st component];000;001
Then we get parity error:
BV10 (Source key parity error)
How is it possible? Is "BU" command not appropriate for obtaining component check value?
Try to check the BU key type.
The key type should be 100 instead of 000
BUFF1[1st component];100;001

Importing RSA Public and Private Keys to VB.NET

I'm a bit new to RSA Encryption. I made an RSA Key Pair using PGPfreeware 6.5.8, and I'm writing a VB.NET code that will encrypt and decrypt a field in an XML file. I made an export to the RSA key that includes both Public and Private Keys and I got the file in .asc extension (For ASCII). and I got the public and private keys in this format:
-----BEGIN PGP PRIVATE KEY BLOCK-----
Version: PGPfreeware 6.5.8 for non-commercial use <http://www.pgp.com>
lQOfA1Tnk1QAAAEIANl3u0UiHAEShaaHRqqL+5nFsrJSHSsRWnPbYjbT7CeJro6Z
Yiwd897w2UW5e7f9sBE6wQBg5qxPodP/kE+70xOlNcCRoV2NexoO8ldDWsm6Sb8s
nB5Paa3cvjC76NZL8E9lGkaPYICJIzN2LtDsgYtYzNnpL4hJ9lHBjeYFr8PGgkQO
7gnVSCGJvDfo9Ov+mmq94aS8eIfMSkyy58zGU4qifbiNF8vBDYhB03H+sdmEDhGx
WH+oWp5LWOgIytW/ZKRuALU75omyeBhVz+nVxziXl1cQR1cahG3fGpaEZDs3SW2t
GDnL2T/z0ED+HVh86yId2+pFimkWlmMiQqqSOK0ABREBod8mktdzj5IH+PvIArUB
4zUTzhvO9WOW5nE62EWDaOiMvofdTDqNHwNkL8JZvSt09wwT24KOhMQqJOgjI0xF
Wl6abL4gsiQ8f7Dy7Fj5+rgepsd9lrAbDPvk5xsy47YMsoPClADfmzWUdaFrLZYc
ZYDPIYwLuzwhkl7qr14WGBY3OKRP9e/oU2oD2AtF2M0tMvaaaE5qiR1+HtpmNy1s
N/fZzUOUOyjypKXWIBHG6gEfm8MfxkYxECnPkHWWjwWCKe4lFw2hnKKhjjC64kSH
asqkZDQ5OekT+icb5H4J94pcn9L4xbwQGpIenPuCYbU2WiJPKhdt1w9C9EsWavpG
4lDvjPxFC8jlZQQALns8/MdcoX8eoOZvse3Iy++lQGNix6CzaKbet4mBRHMCyUD/
HTt0BQVi7fF4u9/edXuQvN/DIZxhwxYoiZB2P18zhkqyhXPUUQMEeDuf4KazaV/0
TfPJ9PC+9WwL4jfrNw1DywKQB1nhz/P54leQbvXdp4/4hlXQxXIj9Jjriz4EANlD
I/WFS87GZtTKJdIQbu7CtyQIF1Ykob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8wmNZLL114gwYrmYPPdBtvqyKuTNjubu3jFX6WYrC4F7
Yi713XwnjS810YIeVo00dUOEnyBzDhLaRDLuWB4cQw3dpD7iRf0xz4yIWsCjRFj1
p7ZDpjfSVi6rDWBWgb2Vlh0jcY3wXuE5EZAAgPzBAmHWFxmegDfeIkpN243BWjrf
w3cqJLJvkMxU4DE=
=ds/P
-----END PGP PUBLIC KEY BLOCK-----
When I tried to pass the public and private keys to my RSACryptoServiceProvider object, I found out that these keys are in a form that is not available for .NET to deal with them; .NET deals with XML Public and Private Keys only. I searched through the internet and found out that the keys in this format are a result of converting the original text using Base64, so I tried converting them back to normal texts instead of Base64 texts so I can -hopefully- import them to my object, but I got a FormatException saying: invalid char in a Base-64 string. What am I doing wrong? and how exactly can I make my files work as the Public and Private Keys for my RSA object?
Thank you.