Skip to content

Instantly share code, notes, and snippets.

@Frank-Buss
Created July 22, 2024 20:15
Show Gist options
  • Save Frank-Buss/c5c475a442d842126b88edf796bbd595 to your computer and use it in GitHub Desktop.
Save Frank-Buss/c5c475a442d842126b88edf796bbd595 to your computer and use it in GitHub Desktop.
testing signing and verifying a file of zeros
# create a new private key
frank@hal9000:~/tmp$ openssl genpkey -algorithm RSA -out private_key.pem -pkeyopt rsa_keygen_bits:2048
..+.+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*.+.........+.+..+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*.....+..+...+....+......+..+...+.......+..+....+..+...+....+..+......+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
.+..+.........+......+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*......+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*.....+.........+....+.....+..........+..+.........+....+..+............+.+..+.......+.....+.+...............+..+............+...+...+.+......+............+...............+..+.............+........+...+......+....+......+........+...+..........+............+..+....+..+...+....+..+....+......+.....+...+.+.....+................+.......................+.+.........+...........+.+...+..+.............+......+..............+...+....+........+.+..+.......+.....+.......+.........+.....+....+..+...+...+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# extract the public key from it
frank@hal9000:~/tmp$ openssl rsa -pubout -in private_key.pem -out public_key.pem
writing RSA key
# create a file with 10000 zeros
frank@hal9000:~/tmp$ dd if=/dev/zero of=driver.sys bs=1 count=10000
10000+0 records in
10000+0 records out
10000 bytes (10 kB, 9.8 KiB) copied, 0.0133372 s, 750 kB/s
# sign the file
frank@hal9000:~/tmp$ openssl dgst -sha256 -sign private_key.pem -out signature.der driver.sys
# test the signature
frank@hal9000:~/tmp$ openssl dgst -sha256 -verify public_key.pem -signature signature.der driver.sys
Verified OK
# show the signature
frank@hal9000:~/tmp$ xxd signature.der
00000000: 6433 530c d8e1 6c96 d142 07af 58b5 0a46 d3S...l..B..X..F
00000010: f54b 68d0 5e1b b730 35d0 f6b5 cc93 64cc .Kh.^..05.....d.
00000020: 8ce0 bfd3 fe2b b6de dcc7 5eeb 686f 5bc2 .....+....^.ho[.
00000030: a45c ddc7 67c8 4b39 a546 fced 4d80 7cfd .\..g.K9.F..M.|.
00000040: 1878 b2b1 faf0 f1eb a335 9c62 3ad0 ecd3 .x.......5.b:...
00000050: 03a8 c1a9 6308 0086 b0ff a656 ec58 c0f4 ....c......V.X..
00000060: 8bed 355a a9cf 37f3 5c43 a0b3 cf82 93b8 ..5Z..7.\C......
00000070: 3bdc f9c0 247a f65f 183e d069 844c 4ee1 ;...$z._.>.i.LN.
00000080: 8c58 5445 f2f3 d5fb 7514 5da2 bb70 ed07 .XTE....u.]..p..
00000090: ff6f 3d0e 2b4b 006d 6e7d 061a f4ea cd3f .o=.+K.mn}.....?
000000a0: 3004 1349 9812 ecc8 33c0 205e 682d 5664 0..I....3. ^h-Vd
000000b0: 59f5 6751 30f4 85ec 8f54 6c55 8514 ffeb Y.gQ0....TlU....
000000c0: 1368 337c dff7 5beb 5208 d6bc 7353 5d5e .h3|..[.R...sS]^
000000d0: d784 4c63 eeab 8a82 cb7a e422 36c1 f5d8 ..Lc.....z."6...
000000e0: ece1 b3d9 c0e9 1c64 672f 5791 e9ef 4d2c .......dg/W...M,
000000f0: e882 e2c9 8863 dfe9 f95a 0d76 8c7f 0870 .....c...Z.v...p
frank@hal9000:~/tmp$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment