I want to send the .p12 file of APNS certificate to One Signal API, but I need first to convert the .p12 file to base64 string. How do I do that? The API documentation is below: https://documentation.onesignal.com/reference#create-an-app
Convert p12 APNS certificate to base64 string
Asked Answered
The script I am building is in Node. –
Catgut
The script that I have tried but did not work: new Buffer(fs.readFileSync(__dirname + "/ios_push_certificate.p12", 'binary')).toString('base64') –
Catgut
new Buffer(fs.readFileSync(__dirname + "/ios_push_certificate.p12")).toString('base64')
That is the correct script after all.
If you're on a Mac you can use the base64 utility that comes with Mac.
base64 -i certificate.p12 -o outputfile
Is it possible to reverse this process? –
Coopersmith
I mean base64 to p12 –
Coopersmith
@Coopersmith
base64 --decode -i outputfile > certificate.p12
–
Tempting You can use this on Linux
base64 file.p12
To write the base64 output to any file, you can use this
base64 file.p12 > output.base64
Note: This works for any files not only .p12
This depends on the programming language you are using.
For example, here's how to do it in Ruby:
base64_encoded_p12 = Base64.encode64(File.read('/path/to/your/file.p12'))
new Buffer(fs.readFileSync(__dirname + "/ios_push_certificate.p12")).toString('base64')
That is the correct script after all.
© 2022 - 2024 — McMap. All rights reserved.