项目作者: mukeshkdangi

项目描述 :
implementation of RSA and (Advanced Encryption Standard) AES
高级语言: Python
项目地址: git://github.com/mukeshkdangi/encypt_aes.git
创建时间: 2019-03-13T23:32:10Z
项目社区:https://github.com/mukeshkdangi/encypt_aes

开源协议:

下载


screenshot

encypt_aes

AES Encryption

Implement a system that uses AES to encrypt data and RSA to protect AES keys. You will
need to write one program to generate RSA keys, and a second one that uses the RSA keys to perform the
encryption and decryption of messages.

Step 1

  • generate Bob/Alice key pair(private and public key) alice.pub and alice.prv
    1. python genkeys.py alice

    Step 2

  • Encrypt message.txt file using AES and also encrypt AES key using RSA 2049
  • Store the cipher text in message.cip
    1. python AESTest.py -e alice.pub message.txt message.cip

Step 3

  • Decrypt message.cip file using alice.prv to message.txt file
    1. python AESTest.py -d alice.prv message.cip message.txt

Example

  1. Uses:
  2. mukesh@localhost in ~/Downloads/CSCI531_HW_3 on master [!?$]$ python genkeys.py bob
  3. ********* generating p prime...........
  4. ********* generating q prime..................
  5. Storing......... bob.pub
  6. Storing.......... bob.prv
  7. mukesh@localhost in ~/Downloads/CSCI531_HW_3 on master [!?$]$ python genkeys.py alice
  8. ********* generating p prime...........
  9. ********* generating q prime..................
  10. Storing......... alice.pub
  11. Storing.......... alice.prv
  12. mukesh@localhost in ~/Downloads/CSCI531_HW_3 on master [!?$]$ cat message.txt
  13. This is Mukesh This is Mukesh This is Mukesh This is Mukesh This is Mukesh This is Mukesh This is Mukesh This is Mukesh This is Mukesh This is Mukesh This is Mukesh This is Mukesh This is Mukesh This is Mukesh This is Mukesh This is Mukesh This is Mukesh This is Mukesh This is Mukesh This is Mukesh
  14. mukesh@localhost in ~/Downloads/CSCI531_HW_3 on master [!?$]$ python crypt.py -e bob.pub message.txt message.cip
  15. Encryption of message.txt file is done. cipher text is present in message.cip file
  16. Process is done
  17. mukesh@localhost in ~/Downloads/CSCI531_HW_3 on master [!?$]$ python crypt.py -d bob.prv message.cip message.txt
  18. plaintext This is Mukesh This is Mukesh This is Mukesh This is Mukesh This is Mukesh This is Mukesh This is Mukesh This is Mukesh This is Mukesh This is Mukesh This is Mukesh This is Mukesh This is Mukesh This is Mukesh This is Mukesh This is Mukesh This is Mukesh This is Mukesh This is Mukesh This is Mukesh
  19. Decryption of message.cip file is done. plain text is in message.txt file
  20. Process is done
  21. mukesh@localhost in ~/Downloads/CSCI531_HW_3 on master [!?$]$ cat message.txt
  22. This is Mukesh This is Mukesh This is Mukesh This is Mukesh This is Mukesh This is Mukesh This is Mukesh This is Mukesh This is Mukesh This is Mukesh This is Mukesh This is Mukesh This is Mukesh This is Mukesh This is Mukesh This is Mukesh This is Mukesh This is Mukesh This is Mukesh This is Mukesh
  23. Using Alice Key with message2.txt
  24. mukesh@localhost in ~/Downloads/CSCI531_HW_3 on master [!?$]$ cat message2.txt
  25. I have strong grasp of technology as well as business skills. Since in my previous role i had interacted with business leads and the country manager of our Asia pacific business as well as their technology teams.
  26. mukesh@localhost in ~/Downloads/CSCI531_HW_3 on master [!?$]$ python crypt.py -e alice.pub message2.txt message2.cip
  27. Encryption of message.txt file is done. cipher text is present in message.cip file
  28. Process is done
  29. mukesh@localhost in ~/Downloads/CSCI531_HW_3 on master [!?$]$ python crypt.py -d alice.prv message2.cip message2.txt
  30. plaintext I have strong grasp of technology as well as business skills. Since in my previous role i had interacted with business leads and the country manager of our Asia pacific business as well as their technology teams.
  31. Decryption of message2.cip file is done. plain text is in message.txt file
  32. Process is done
  33. mukesh@localhost in ~/Downloads/CSCI531_HW_3 on master [!?$]$ cat message2.txt
  34. I have strong grasp of technology as well as business skills. Since in my previous role i had interacted with business leads and the country manager of our Asia pacific business as well as their technology teams.

Project Details

To complete the project, you will need to write two Python programs:
-[x] 1. genkeys.py — generate RSA public and private keys.
 The program takes a single command line argument: the name of the user for whom the keys will
be generated. For test purposes, use the user names alice and bob.

 The program must be runnable directly from the command shell, e.g., ./genkeys.py alice

 The program must generate an RSA public/private key pair using your own code (you cannot
import RSA code from another module such as PyCrypto). It must use random.SystemRandom or
os.urandom() as the source of pseudo-random bytes. The keys must be of practical cryptographic
size.

 The program must produce two output files, one containing the RSA private key (e.g., alice.prv)
and the other one containing the RSA public key (e.g., alice.pub). The format of the key files is
up to you.

 You will need to write code to compute modular inverse and to test whether a number is prime.

  1. crypt.py — encrypt and decrypt data using AES-128 and RSA.

 The program takes four command line arguments: a single flag (-e or -d) indicating whether the
program will encrypt or decrypt a message, the name of the public or private key file to use
(generated by keygen.py), the name of the file to encrypt or decrypt, and the name of the output
file. For example, the following command will encrypt the file secret.txt using Alice’s public key
file alice.pub to produce the cipher text file secret.cip:

./crypt.py -e alice.pub secret.txt secret.cip
Then the following command would decrypt the file secret.cip:
./crypt.py -d alice.prv secret.cip secret.txt

Some random number examples (p,q):
104087 104089 104107 104113 104119 104123 104147 104149 104161 104173
104179 104183 104207 104231 104233 104239 104243 104281 104287 104297
104309 104311 104323 104327 104347 104369 104381 104383 104393 104399
104417 104459 104471 104473 104479 104491 104513 104527 104537 104543
104549 104551 104561 104579 104593 104597 104623 104639 104651 104659
104677 104681 104683 104693 104701 104707 104711 104717 104723 104729

 To encrypt a file, the program must generate a random key K for AES-128 using
random.SystemRandom or os.urandom(), use the key K with AES-128 to encrypt the data from
the input file, use RSA with the public key file specified on the command line to encrypt K (we
refer to the encrypted K as K’ in the following), and write the encrypted data and K’ to the output
file. The format of the output file (how to store K’ along with the encrypted data) is your choice.

 To decrypt a file, the program must read the encrypted data and K’ from the input file, RSAdecrypt K’ to recover the key K, use K with AES-128 to decrypt the data, and write the decrypted
data to the output file.

 You must write the RSA code; you may not import RSA code from another module such as
PyCrypto.

 You must choose an appropriate mode of operation for AES-128.
In addition to the two Python programs, you must provide a written description of the design of your
programs and a screen capture of a session demonstrating that your programs work. For example, a screen
capture of the following sequence of commands would be sufficient (this assumes the files message.txt
and message2.txt already exist):

  1. ./genkeys.py alice
  2. ./genkeys.py bob
  3. cat message.txt
  4. ./crypt.py -e bob.pub message.txt message.cip
  5. cat message.cip
  6. ./crypt.py -d bob.prv message.cip message.txt
  7. cat message.txt
  8. cat message2.txt
  9. ./crypt -e alice.pub message2.txt message2.cip
  10. cat message2.cip
  11. ./crypt -d alice.prv message2.cip message2.txt
  12. cat message2.txt