'Convert p12 APNS certificate to base64 string

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



Solution 1:[1]

new Buffer(fs.readFileSync(__dirname + "/ios_push_certificate.p12")).toString('base64')

That is the correct script after all.

Solution 2:[2]

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

base64 -i certificate.p12 -o outputfile

Solution 3:[3]

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'))

Solution 4:[4]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 anestis
Solution 2 Nuno Gonçalves
Solution 3 Gdeglin
Solution 4 harshaaliaschinna