Code Monkey home page Code Monkey logo

grado_informatica_criptografia's Introduction

grado_informatica_criptografia

A repo hosting all the assigment and source code of the Cryptography subject. ETSIIT

Example of P3/Ej7. Sign files with RSA

Here is the help:

usage: ej7.py [-h] -d <path> [-g <key size>] [-s <file> <priv key>]
              [-v <original file> <signed file> <pub key>]

Generate RSA keys, sign and verify signed files

optional arguments:
  -h, --help            show this help message and exit
  -d <path>, --directory <path>
                        Where to store the keys and signature
  -g <key size>, --genkeys <key size>
                        Generate RSA keys
  -s <file> <priv key>, --sign <file> <priv key>
                        Sign a file
  -v <original file> <signed file> <pub key>, --verify <original file> <signed file> <pub key>
                        Verify a signed file

Once downloaded, you can generate your keys with:

$ python ./ej7.py -d ./ -g 2048

And you will see something like this:

Generating keys...
Done, keys placed in ./
Your public key:
NjY4NzMzOTk2NDY3NDM0OTg0MjI1NTExOTU5NDE4NTE0OTA0MzIyNDgyNDYzODk0NDQzOTM0NzA0OTc4MjEzMzUzMDMwMjA4MTc0Nzg4ODA1N........

Your private key:
NTM0OTg3MTk3MTczOTQ3OTg3MzgwNDA5NTY3NTM0ODExOTIzNDU3OTg1OTcxMTE1NTU1MTQ3NzYzOTgyNTcwNjgyNDI0MTY2NTM5ODMxMDQ0M........

Once you have your public and private key, in the path you choose, you can sign a file with:

$ python ./ej7.py -d ./ -s file.txt rsa.priv

The output would be:

Signing file...
Sign placed in ./file.txt.signed here is the sign
MjAyMzMzNDcyNDA2MDE2NDMzODE5NTU2NjE4MjkwMjg3NzkzMDM4NzE0MTE.......................

Finally, to check that a file was signed correctly:

$ python ./ej7.py -d ./ -v file.txt file.txt.signed rsa.pub

Verifying signature...
File is correctly signed
Original signature: 
6489173261045097199711934183582747376698259832904786118783303916308307801147620581729652089220119753020693094141877657507765409178638893860418373696327180
Current signature 
6489173261045097199711934183582747376698259832904786118783303916308307801147620581729652089220119753020693094141877657507765409178638893860418373696327180

If the file was corrupted, when the above command is executed, you will see:

Verifying signature...

##########################
## INVALID SIGNATURE!!! ##
##########################

Original signature: 
6091672226240801698371810859476188289341568805009997190131273579330832769362617745024212278025102239097390392429061669931887332626496467275750968867723954
Current signature 
6489173261045097199711934183582747376698259832904786118783303916308307801147620581729652089220119753020693094141877657507765409178638893860418373696327180

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.