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
Asked
Active
Viewed 1.4k times
7

Terry Windwalker
- 1,343
- 2
- 16
- 36

anestis
- 931
- 3
- 9
- 24
-
The script I am building is in Node. – anestis Sep 21 '16 at 10:08
-
The script that I have tried but did not work: new Buffer(fs.readFileSync(__dirname + "/ios_push_certificate.p12", 'binary')).toString('base64') – anestis Sep 21 '16 at 10:09
4 Answers
17
If you're on a Mac you can use the base64 utility that comes with Mac.
base64 -i certificate.p12 -o outputfile

Nuno Gonçalves
- 6,202
- 7
- 46
- 66
-
1
-
1
-
1@SPatel ```base64 --decode -i outputfile > certificate.p12``` – Dnyaneshwar Harer Apr 14 '23 at 04:09
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'))

Gdeglin
- 12,432
- 5
- 49
- 65
0
new Buffer(fs.readFileSync(__dirname + "/ios_push_certificate.p12")).toString('base64')
That is the correct script after all.

anestis
- 931
- 3
- 9
- 24
0
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

harshaaliaschinna
- 186
- 3
- 6