Convert p12 APNS certificate to base64 string
Asked Answered
C

4

10

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

Catgut answered 20/9, 2016 at 6:39 Comment(2)
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
C
1
new Buffer(fs.readFileSync(__dirname + "/ios_push_certificate.p12")).toString('base64')

That is the correct script after all.

Catgut answered 22/9, 2016 at 12:38 Comment(0)
W
19

If you're on a Mac you can use the base64 utility that comes with Mac.

base64 -i certificate.p12 -o outputfile
Wiedmann answered 9/5, 2020 at 12:0 Comment(3)
Is it possible to reverse this process?Coopersmith
I mean base64 to p12Coopersmith
@Coopersmith base64 --decode -i outputfile > certificate.p12Tempting
T
2

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

Tort answered 15/10, 2021 at 8:33 Comment(0)
A
1

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'))
Alexandretta answered 21/9, 2016 at 0:46 Comment(0)
C
1
new Buffer(fs.readFileSync(__dirname + "/ios_push_certificate.p12")).toString('base64')

That is the correct script after all.

Catgut answered 22/9, 2016 at 12:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.