Skip to content

Instantly share code, notes, and snippets.

@why-not
Last active February 3, 2022 05:49
Show Gist options
  • Save why-not/856ada1afaed6f097c4e4617c1af9237 to your computer and use it in GitHub Desktop.
Save why-not/856ada1afaed6f097c4e4617c1af9237 to your computer and use it in GitHub Desktop.
Sign and Verify Using Public/Private Keys
# generate private key
openssl genrsa -out private_key.pem 4096
# extract public key
openssl rsa -in private_key.pem -pubout > public_key.pub
# sign using private key
openssl dgst -sign private_key.pem -keyform PEM -sha256 -out VGG_ILSVRC_16_layers.caffemodel.sign -binary VGG_ILSVRC_16_layers.caffemodel
# extract using public key
openssl dgst -verify public_key.pub -keyform PEM -sha256 -signature VGG_ILSVRC_16_layers.caffemodel.sign -binary VGG_ILSVRC_16_layers.caffemodel
# tamper with the model
echo "Tamper" >> VGG_ILSVRC_16_layers.caffemodel.tamper
# verify tampered file
openssl dgst -verify public_key.pub -keyform PEM -sha256 -signature VGG_ILSVRC_16_layers.caffemodel.sign -binary VGG_ILSVRC_16_layers.caffemodel.tamper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment