Skip to content

Commit 2d803a5

Browse files
committed
Allows you to convert certificate files to hex representation
.der files to a formatted hex string which can be included in C code
1 parent e4fdbd0 commit 2d803a5

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

CertToHex.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import binascii
2+
filename = 'Path\\To\\File\\Cert.der'
3+
with open(filename, 'rb') as f:
4+
content = f.read()
5+
6+
hexData = binascii.hexlify(content)
7+
hexList = list(''.join(map(chr,hexData)))
8+
outString = ''
9+
caCertLen = 0
10+
11+
x = len(hexList)
12+
for i in range(0, (x-1), 2):
13+
first = hexList[i]
14+
second = hexList[i+1]
15+
outString = outString + '0x' + first + second + ', '
16+
caCertLen = caCertLen + 1
17+
18+
outString = outString[:-2] #remove last comma and space
19+
20+
print(outString)
21+
print('Cert length = ' + str(caCertLen))

0 commit comments

Comments
 (0)