I have a string:
'MIIciwYJKoZIhvcNAQcCoIIcfDCCHHgCAQExCzAJBgUrDgMCGgUAMIIMLAYJKoZIhvcNAQcBoIIMHQSCDBkxggwVMAoCAQgCAQEEAhYAMAoCARQCAQEEAgwAMAsCAQECAQEEAwIBADALAgEDAgEBBAMMATEwCwIBCwIBAQQDAgEAMAsCAQ4CAQEEAwIBajALAgEPAgEBBAMCAQAwCwIBEAIBAQQDAgEAMAsCARkCAQEEAwIBAzAMAgEKAgEBBAQWAjQrMA0CAQ0CAQEEBQIDAYahMA0CARMCAQEEBQwDMS4wMA4CAQkCAQEEBgIEUDI0NzAYAgEEAgECBBDTMQqCVP9JNijerDz8F4JOMBsCAQACAQEEEwwRUHJvZHVjdGlvblNhbmRib3gwGwIBAgIBAQQTDBFwb3RhdG9sYWJzLmJhbmFuYTAcAgEFAgEBBBSwSAEz57UFwfMJ0Yf7USotU0nrhDAeAgEMAgEBBBYWFDIwMTYtMTItMjBUMTg6MzY6NDNaMB4CARICAQEEFhYUMjAxMy0wOC0wMVQwNzowMDowMFowQQIBBwIBAQQ5g8RXC0VL8JCqCTi1pxOIyv/ZJRsukymatvDJGhALBUHWOplLmpsZy4vcgC1cIpOVcooNg8JcbeJDMFgCAQYCAQEEUOBY1PXnuP8l20SwT0bMOcWf9H9Xo6lxxSVDuDrOlAiHm5Pcju4eWs7iAVJOkItqhVt0gRMveJDryC1iokiqOyUC87OSM/RElc6lljTb+yOlMIIBbQIBEQIBAQSCAWMxggFfMAsCAgatAgEBBAIMADALAgIGsAIBAQQCFgAwCwICBrICAQEEAgwAMAsCAgazAgEBBAIMADALAgIGtAIBAQQCDAAwCwICBrUCAQEEAgwAMAsCAga2AgEBBAIMADAMAgIGpQIBAQQDAgEBMAwCAgarAgEBBAMCAQMwDAICBq4CAQEEAwIBADAMAgIGsQIBAQQDAgEAMBICAgavAgEBBAkCBwONfqb
I can't make any sense of it unless I decode it. However, I've tried installing the base64 npm package, and the utf8 package as well but it is complaining that _utf2.default.decode is not a function. (In \'_utf2.default.decode(bytes)\', \'_utf2.default.decode\' is undefined).
https://github.com/mathiasbynens/base64
https://github.com/mathiasbynens/utf8.js#utf8decodebytestring
import base64 from 'base-64';
import utf8 from 'utf8';
const bytes = base64.decode(validationData);
const text = utf8.decode(bytes); // <----- fails here
console.log("base64: ", text);
Background: trying to implement in app purchases using this: https://github.com/chirag04/react-native-in-app-utils but the receiptData is base64 encoded
If you're trying to decode it and render it as an image component you can do it like this:
const base64 = 'data:image/png;base64, *put your string here*'
<Image source={{uri: base64}} />
I had the same problem.
I found this repository, which appears to be pretty old, but also worked. I don't receive the header (which I didn't need), but I do recieve the payload/data.
I did the following:
npm install jwt-decode --save
Then, in my app:
var jwtDecode = require('jwt-decode');
// Where necessary elsewhere in the code
let decoded = jwtDecode(token);
console.log('Decoded:',decoded);
Related
Can someone tell me what I am doing wrong with trying to upload an image to blob storage? Below is my code.
print(type(img['image'])) #Output is <class 'bytes'>
connection_string = get_blob_connection_string()
blob_service_client = BlobServiceClient.from_connection_string(connection_string)
blob_client = blob_service_client.get_blob_client(container="images", blob=img['id'])
exists = blob_client.exists()
if (exists == False):
result = blob_client.upload_blob(img['image'], blob_type="blockblob")
print(result)
When inserting the blob, it throws the error
quote_from_bytes() expected bytes
This error makes no sense, I gave it bytes. What am I missing?
After reproducing from my end, I have received the same issue. You are receiving this error because of incompatible type of the file (i.e., file format).
After changing the below line to the correct format I could able to achieve your requirement.
blob_client = blob_service_client.get_blob_client(container="images", blob=img['id'])
Below is the correct format
blob_client=blob_service_client.get_blob_client(container='container', blob='<LOCAL FILE PATH>');
Below is the complete code that worked for me
from azure.storage.blob import BlobServiceClient
from PIL import Image
connection_string = "<CONNECTION STRING>"
blob_service_client = BlobServiceClient.from_connection_string(connection_string)
blob_client=blob_service_client.get_blob_client(container='container', blob='<LOCALPATH>');
with open(file='<PATH IN YOUR STORAGE ACCOUNT WITH FILE NAME>', mode="rb") as data:
blob_client.upload_blob(data)
RESULTS:
I execute the Tendermint request /unconfirmed_txs to get pending transactions data and I get a list of b64 encoded transactions like this:
CsQECpAECh8vZXRoZXJtaW50LmV2bS52MS5Nc2dFdGhlcmV1bVR4EuwDCqUDChovZXRoZXJtaW50LmV2bS52MS5MZWdhY3lUeBKGAwgCEg01MDc3OTQ2NTQxMzY0GPbZDCIqMHgxNDU4NjNFYjQyQ2Y2Mjg0N0E2Q2E3ODRlNjQxNkMxNjgyYjFiMkFlKhU0MDAwMDAwMDAwMDAwMDAwMDAwMDAy5AF/82q1AAAAAAAAAAAAAAAAAAAAAAAAAAAAfvEOe1XqTQ9Ynq8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAAK5tNYq1CNfuvRh/6NqF6Zzkg6PtAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAMd7WUoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAFx/ilcNV47YTmP9+nse5y3q4a4jAAAAAAAAAAAAAAAA3XPeoQq8K/+ZxgiC7FsrgbsdxbI6AVZCIBX0RwQW5LaC1LZG0W5mHid2Dsx/8FQn0r9IhHrWBAVxSiBLOhtk5OAdcCGBHaLUHK8rKEpL1bgtBRYxG/if+UesIxpCMHhlZGRjOWMxMWVkY2Q1NTY4YWZlOWM0Y2ZmYWNjMmU4ZjBhMGNlNjFiMDczMDE4OTQ1NzEyZDMwNTU3ZDBjMTUw+j8uCiwvZXRoZXJtaW50LmV2bS52MS5FeHRlbnNpb25PcHRpb25zRXRoZXJldW1UeBImEiQKHgoHYmFzZWNybxITMTA1NjgxMjA3ODI5NTU5Mjk1MhD22Qw=
How can I decode these transactions in Golang to get all the transaction data ( if possible in the Transaction struct of go-ethereum ) ?
After some research I understood that I have to use some codec and register them with some functions with the lib but I don't found a good code exemple for my use case and really don't understand how it works.
I also tried the library github.com/calvinlauyh/cosmosutils to decode transactions but I get the error: "unable to resolve type URL /ethermint.evm.v1.MsgEthereumTx: tx parse error"
Thanks !
transactions data is encode in base64, check the below code for decoding.
const { sha256 } = require("#cosmjs/crypto")
const { toHex} = require("#cosmjs/encoding")
const base64EncodedTrx ="CpIBCo8BChwvY29zbW9zLmJhbmsudjFiZXRhMS5Nc2dTZW5kEm8KLWNvc21vczEyeHQ0eDQ5cDk2bjlhdzR1bWp3eXAzaHVjdDI3bndyMmc0cjZwMhItY29zbW9zMXV0MncwbTN4YTd6MnJ2bmR2MjNwdGh2OXFjN2hrc3g2dGtmOXVxGg8KBXVhdG9tEgYyNTAwMDASaQpRCkYKHy9jb3Ntb3MuY3J5cHRvLnNlY3AyNTZrMS5QdWJLZXkSIwohAyhu2k5/x5GSSsNDGaahT1pMDK7Yk65LnRJo81IH166REgQKAggBGKMdEhQKDgoFdWF0b20SBTczMzU1EIu9BBpAM6HTxgkO1dRiuVU3TD23MzfKcyWOxhM4VlZKulLmFy4dcbpkaauXeuOlptAl9sbRKGozVr0Z87VPT/LIQCBrDw==";
const sha256v= sha256(Buffer.from(base64EncodedTrx,'base64'));
const txHash = toHex(sha256v)
//trx signature
console.log(txHash)
I have a Nuxt application that needs to retrieve some information from a Spring Boot-based auth service.
Right now I sign a text message on the Nuxt app (the auth server is aware of that text message), using node-forge, and then I send it encrypted and with the signature for verification on the auth service.
The problem is that the auth service keeps telling me that the size of the signature is wrong, with a java.security.SignatureException: Signature length not correct: got 3XX but was expecting 256.
Here is the code generating the encrypted message and signature on the Nuxt side:
var md = forge.md.sha256.create();
md.update("123"); // for example purposes
var sign = pPrivateKey.sign(md);
var digestBytes = md.digest().bytes();
console.log("Signature:", sign );
console.log("Encrypted:", digestBytes);
console.log("Encrypted B64:", Buffer.from(digestBytes).toString("base64"));
var keyAuthB64Url = Buffer.from(digestBytes).toString("base64url");
var signB64Url = Buffer.from(sign).toString("base64url");
var jwt = await axios.get(process.env.URL + "/auth", { params: { encrypted: keyAuthB64Url, signature: signB64Url } });
On the auth service I have the following code:
byte[] messageBytes = Base64.getUrlDecoder().decode(encryptedMessage);
byte[] signatureBytes = Base64.getUrlDecoder().decode(signature);
Signature sign = Signature.getInstance("SHA256withRSA");
sign.initVerify(certPublicKey);
sign.update(messageBytes);
boolean verified = sign.verify(signatureBytes);
if (!verified) {
throw new Exception("Not verified!");
}
From all the debugging I have done, it seems like the Spring Boot app has a problem with the signature generated by node-forge on the Nuxt side, with a signature generated in the Spring Boot app the verification works.
There are several issues:
First, the bug that was already mentioned in the comment: While the NodeJS code does not hash implicitly, the Java side does. Therefore, hashing must not be done explicitly on the Java side:
byte[] messageBytes = "123".getBytes("utf-8");
...
sign.update(messageBytes); // Fix 1: Don't hash
Also, in the NodeJS code, sign() returns the data as a bytes string, which must therefore be imported into a NodeJS buffer as a 'binary':
var keyAuthB64Url = Buffer.from(digestBytes, "binary").toString("base64url"); // Fix 2: Import via 'binary' encoding
Without explicit specification of the encoding, a UTF-8 encoding is performed by default, which irreversibly corrupts the data.
And third, latin1 is implicitly used as encoding when generating the hash in the NodeJS code. Other encodings must be specified explicitly, e.g. for the common UTF-8 with utf8:
md.update("123", "utf8"); // Fix 3: Specify the encoding
For the example data 123 used here, this fix has no effect, which changes as soon as characters with a Unicode value larger than 0x7f are included, e.g. 123§. Note that there is little margin for error in the specification of the encoding, e.g. utf-8 would be ignored (because of the hyphen) and latin1 would be used silently.
With these fixes, verification with the Java code works.
when I encode my file in UTF8 I can't use the emoji anymore.
if (_local.temp.pycx !== undefined) {
_local.temp.pycx.reactions.find(x.emoji === "ðŸ").remove(user);
};
if (_local.lobby.players.length === 3) {
_local.temp.pycx = await channel.send("React to this message to start the game. [Everyone must vote to start]");
_local.temp.pycx.react("ðŸ");
addReactable(_local.temp.pycx, actions.startGame, "ðŸ");
};
This code works like a charm if the file is in ANSI. But I need UTF8...
I tried to put 🚩 but it doesn't work... Unknown Emoji
What can I do to make it work with UTF8 encode?
Ok, my bad I didn't see there was more weird emoji bellow. It works fine with the unicode emoji.
I am trying to send a jpeg image file through a ZeroMQ connection with pyzmq, but the output is 3 times the size of the input, and no longer a valid jpeg. I load the image and send with...
f = open("test1.jpg",'rb')
strng = f.read()
socket.send(strng)
f.close()
I receive and save with...
message = socket.recv()
f = open("test2.jpg", 'w')
f.write(str(message))
f.close()
I am new to zmq, and I could not find any info on sending images. Has anyone sent images through ZeroMQ, or have any ideas on how to find the problem?
Before sending the file you can "base64" encode it and decode it when received.
Sending:
import base64
f = open("test1.jpg",'rb')
bytes = bytearray(f.read())
strng = base64.b64encode(bytes)
socket.send(strng)
f.close()
Receiving:
import base64
message = socket.recv()
f = open("test2.jpg", 'wb')
ba = bytearray(base64.b64decode(message))
f.write(ba)
f.close()
You can try imagezmq. It's specially built for transporting images using PyZMQ messaging.
Sender
import socket
import imagezmq
sender = imagezmq.ImageSender(connect_to='tcp://receiver_name:5555')
sender_name = socket.gethostname() # send your hostname with each image
image = open("test1.jpg",'rb')
sender.send_image(sender_name, image)
Receiver
import imagezmq
image_hub = imagezmq.ImageHub()
sender_name, image = image_hub.recv_image()
image_hub.send_reply(b'OK')
Zero-copy string manipulations on C-strings
( from enter link description here )
Bytes and Strings
Note
If you are using Python >= 2.6, to prepare your PyZMQ code for Python3 you should use the b'message' syntax to ensure all your string literal messages will still be bytes after you make the upgrade.
The most cumbersome part of PyZMQ compatibility from a user’s perspective is the fact that, since ØMQ uses C-strings, and would like to do so without copying, we must use the Py3k bytes object