I'm trying to encode an Amazon s3 bucket policy in base64 in node.js for the signature (more specifically the StringToSign), but can't seem to get the code right.
I'm using a default policy provided by amazon to test with because they provide the correct base64 encoding. (The example given by amazon)
Their output is eyAiZXhwaXJhdGlvbiI6ICIyMDE1........ (Keeping it short because it's quite long)
I keep getting eyJleHBpcmF0aW9uIjoiMjAxNS0xMi0zMFQx.....
my code to generate this is:
var policyString = JSON.stringify(policy)
var policyBytes = utf8.encode(policyString)
var stringToSign = base64.encode(policyBytes)
where policy is a variable holding the amazon policy in JSON format, and utf8 and base64 are node modules.
This might sound like a novice question but I've been staring at it for awhile now and any hlep would be appreciated!
I decoded the current partial values you have provided
eyAiZXhwaXJhdGlvbiI6ICIyMDE1
eyJleHBpcmF0aW9uIjoiMjAxNS0xMi0zMFQx
Respective outputs were:
{ "expiration": "2015
{"expiration":"2015-12-30T1
As you can see, in your policyString you have removed some spaces. This is the reason for you to get a different output
Related
So I'm trying to find out how a web app works and I was looking at its requests the raw data was encoded like this what is this and how to reproduce it to use their api?
é£Ü-JM[#ÀóÚÀ5"Ò
¿ eyJ4NXQiOiJOVEF4Wm1NeE5ETXlaRGczTVRVMVpHTTBNekV6T0RKaFpXSTRORE5sWkRVMU9HRmtOakZpTVEiLCJraWQiOiJOVEF4Wm1NeE5ETXlaRGczTVRVMVpHTTBNekV6T0RKaFpXSTRORE5sWkRVMU9HRmtOakZpTVEiLCJhbGciOiJSUzI1NiJ9.eyJtaWJQcml2aWxlZ2VzIjoiRk9SQ0VEX09UUCIsInN1YiI6ImxpbGFwbkBjYXJib24uc3VwZXIiLCJreWNTdGF0dXMiOiJ7XCJXeWlnUENXUjJnRDFveGVKeTJvNXNZXCI6XCJjXCJ9IiwiaXNzIjoiaHR0cHM6XC9cL2xvY2FsaG9zdDoxNDI1N1wvb2F1dGgyXC90b2tlbiIsIm1vYmlsZSI6IjA5MTI3NzkwNTI5IiwiYXVkIjoicmpySko5V2RmUTM3X3VlMENfS3JBVkp6MUN3YSIsIlVzZXJPVFBTdGF0dXMiOiJGSU5BTCIsIlBhcnR5SWQiOiI1MzU3NjY3MSIsImF6cCI6InJqckpKOVdkZlEzN191ZTBDX0tyQVZKejFDd2EiLCJzY29wZSI6Im9wZW5pZCIsIkZvcmNlQ2hhbmdlIjoiRmFsc2UiLCJleHAiOjE2NzU3MDkyMDQsImlhdCI6MTY3NTcwODMwNCwianRpIjoiNzExZjMzMTItMmMyNS00NmI4LWFmN2YtZjQ2ZmEwZmRlZjE1In0.fPGGaVObDPuhYOVhAPAk9mw_Vtiyzq-v43iCGuULLioPpuR73eb8f1ufB6Y5ZnX3zsPp7Mq-XkLC0wwiY_6_-ykDg3huNwmI-bpKxB0szQkolpShE0QyqQ93dS8sB5yaB_qoHvzhsWM1_sRfJB3F246MiYietw9UAqJsmFrXAEq2diX2idjNeAc_SuPqNBtd39qw6cUcchW1n8m5VyLXogO9gN5TzVntvmUIh9r047E87Fdm1mXZEiuLEub2ljrrIrK9-zuPmfQx4FuEr8CQOlwvunmALLVjSRK1WsVEFwSW8pmrXvsu0LZOMgEWoSb7zfYYa4m-gbmvMrsuWYQ7CQB P²> Ü¡©DÓW×}ÿº> J
fa_IR
I'm just trying to understand the requests to the server so that I can reproduce them again to use their api.
That is base-64 encoded text. When decoded, this is what I got back:
{"x5t":"NTAxZmMxNDMyZDg3MTU1ZGM0MzEzODJhZWI4NDNlZDU1OGFkNjFiMQ","kid":"NTAxZmMxNDMyZDg3MTU1ZGM0MzEzODJhZWI4NDNlZDU1OGFkNjFiMQ","alg":"RS256"}
{"mibPrivileges":"FORCED_OTP","sub":"lilapn#carbon.super","kycStatus":"{"WyigPCWR2gD1oxeJy2o5sY":"c"}","iss":"https://localhost:14257/oauth2/token" ,"mobile":"09127790529","aud":"rjrJJ9WdfQ37_ue0C_KrAVJz1Cwa","UserOTPStatus":"FINAL","PartyId":"53576671","azp":"rjrJJ9WdfQ37_ue0C_KrAVJz1Cwa","scope":"openid","ForceChange":"False","exp":1675709204,"iat":1675708304,"jti":"711f3312-2c25-46b8-af7f-f46fa0fdef15"}
I'm doing Api integration with Suitescript 2.0. A data encoded with base64 is returned from the Api. Here I need to reach the data I want by decoding the base64 and saving the xml data returned as a .zip and unzip it.
The relevant data can be run in Notepad++ with Plugins > MIME Tools > Decode Base64, saved as zip and opened with unzip.
The script I'm working with is a shcedule script.
I tried the two methods mentioned to decode in Suite Answers.
1- From base64 to UTF_8 with N/encode module (Returned result is completely wrong for this problem)
2 - The solution in the link:
https://netsuite.custhelp.com/app/answers/detail/a_id/41271/kw/base64%20decode
(In this solution, when you save the returned data as zip, it gives an "Unexpected end of the archive" error when opening the zip.)
ArrayBuffer() and atob() are not available in Suitescript.
The thing I know will work is to proxy the call through a Lambda on some external system.
However if your data is already in base64 you might try just creating a file cabinet file and give it the base64 encoded value as its content. Netsuite already handles base64 for files so you might be overworking the issue. It doesn't sound like you are actually processing the xml if your end goal is to save it as a zip.
If this doesn't help see my comments regarding some clarifications you could add to your question.
require(["N/encode"], function(encode){
var txt = encode.convert({
string: "your Base64 string",
inputEncoding: encode.Encoding.BASE_64,
outputEncoding: encode.Encoding.UTF_8
});
}
SuiteScript example
All types of encode
i am using electron and node js and trying to decrypt an encrypted file using crypto js, but i don't want to save it on user's local hard drive, i want to display it on video tag as i am reading it, meaning i don't want to use fs.createWriteStream after decryption, here is what i tried:
const decipher = crypto.createDecipher('des-ecb', 'a password');
const decInput = fs.createReadStream("encrypted video");
var file = decInput.pipe(decipher);
var file2 = fs.createReadStream(file);
is such thing is even possible? if i want to display the video i must have its url for source of video tag, but i can't make an URL for that file, and i cant even read it because it says object is passed to the fs.createReadStream and it says param must be string(path) or buffer or etc...
NOTE: the encryption and decryption works just fine so i ignored the rest of the code...
Similar question might already suit your needs. You already have the stream ready, let frontend reads it so that video is stored in the browser.
so i got the attachment id from the api, and the payload is data in bytes
from https://developers.google.com/gmail/api/v1/reference/users/messages/attachments#resource
The body data of a MIME message part as a base64url encoded string.........
so i tried decoding it with https://github.com/brianloveswords/base64url
and few other base64 plugins - all returing another unreadable string format.
since i wasn't sure if it was an actual file or decoded url i tried exporting contents to a file with known extension without much success, so it should be a download link.
does anyone have any idea how to get a readable format of this string?
payload string sample
1op669AzYx7c9caYxOd0ZWzNE7IqPyUUnmRkib4HPAUbc3FzzEs7xWl6glqXXo2Y_hjSfT9CtS0THzTkf2rZ8UbKU6S
base64 utf8 decoded sample
↑8�k垬☼A��VN��\�>�/i��U�ՁR∟F����A�☺ň<�v¶��C� I-t��]⌂�R☺
string is much muh bigger, testing can be done here for full response https://developers.google.com/gmail/api/v1/reference/users/messages/attachments/get
UPDATE
Solved it
https://stackoverflow.com/a/16350999/7579200
Sounds like you should use the get function.
I am having trouble finding the answer I need for my situation and hoping that someone may be able to help.
Full disclosure, I am pretty new to Python.
What I am trying to achieve is;
Perform a HTTP POST to download a PDF (with Requests, Python 3).
I want to take the stream and give it Google Drive, which will convert back to a PDF and save the file in the Drive folder.
I am ok with the url file request, but I am receiving UnicodeDecodeError on reading the contents. I have tried several files but the same result.
The limitations I have are that I can't install packages (limited to the couple that are provided) and cannot write the output to a file (read-only fs), as I am using Zapier.
This is the (very) basic code I am using;
import requests
url = 'http://unec.edu.az/application/uploads/2014/12/pdf-sample.pdf'
resp = requests.get(url, stream=True)
resp_bin = (resp.content)
return {'output': resp_bin}
Note that the file is just a random file I found for testing purposes.
Error received is; UnicodeDecodeError: 'utf8' codec can't decode byte 0xe2 in position 10: invalid continuation byte
If anyone has a way of making this work without additional packages, that would be great.
Note: I do also have the option of urllib here and alternatively JavaScript (node.js v4.3.2) with fetch.