Cpsc 526 Network Systems Security

Cpsc 526 Network Systems Security

CPSC 526 NETWORK SYSTEMS SECURITY #15 – READING FROM STDIO, ENCRYPTING & DECRYPTING FILES TA: HENRIQUE PEREIRA SYS • https://docs.python.org/3/library/sys.html • sys.stdin.buffer.read( byte_size ) • To write or read binary data from/to the standard streams, use the underlying binary buffer object. For example, to read 32 bytes from standard input, use sys.stdin.buffer.read(32). SIMPLE PYTHON CODE TO COPY A FILE FROM STDIN • Demo CRYPTOGRAPHY • High level recipes and low level interfaces to common cryptographic algorithms such as symmetric ciphers, message digests, and key derivation functions. • https://cryptography.io/en/latest/ • pip install cryptography SYMMETRIC ENCRYPTION - AES • cryptography.hazmat.primitives.ciphers.algorithms.AES(key) • AES (Advanced Encryption Standard) is a block cipher standardized by NIST. AES is both fast, and cryptographically strong. It is a good default choice for encryption. • Parameters: key (bytes) – The secret key. This must be kept secret. Either 128 (16 bytes), 192, (24 bytes) or 256 bits (32 bytes) long. BASIC AES USAGE • Demo MULTIPLE OF THE BLOCK LENGTH PROBLEMS? • Padding is the solution. PADDING • https://cryptography.io/en/latest/hazmat/primitives/padding/ • Symmetric Padding • cryptography.hazmat.primitives.padding.PKCS7 • PKCS7 padding is a generalization of PKCS5 padding (also known as standard padding). PKCS7 padding works by appending N bytes with the value of chr(N), where N is the number of bytes required to make the final block of data the same size as the block size. AES + PADDING • Demo ENCRYPTING & DECRYPTING FILES • Encrypting a file: • https://github.com/crazyguitar/pysheeet/blob/master/docs/notes/python-crypto.rst#using-aes- cbc-mode-encrypt-a-file • Decrypting a file: • https://github.com/crazyguitar/pysheeet/blob/master/docs/notes/python-crypto.rst#using-aes- cbc-mode-decrypt-a-file CONSIDERATIONS • Both codes encrypt and decrypt full files. • Assignment #4 files cannot be encrypted/decrypted this way. • You are reading the files from STDIN • You don`t know the size of the input • You can`t save your input to disk because of that • You could probably use that logic to encrypt/decrypt small “slices” of your input file. • And reassemble those slices when decrypting.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    11 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us