AES Code Example

Size: px
Start display at page:

Download "AES Code Example"

Transcription

1 210 Figure Block cipher chaining modes AES Code Example Now that we have covered block ciphers and CBC, we provide a simple Java code example that can encrypt and decrypt using AES in CBC mode. Our code will show you how to practically use symmetric encryption, and will provide an example that shows it in action. How AES encryption is done may differ from one language to another, but our example will give you a general flavor as to what code that uses cryptographic libraries looks like. Our Java class is called AESEncrypter. It is a command-line utility that can create an AES key, encrypt with the key, and decrypt with the key. The first argument to the command-line tool specifies what it should do: create a key, encrypt, or decrypt. It stores keys in files, and accepts the name of the key file as the second parameter on the command line. It accepts its input from stdin and writes its output to stdout. The following are some example commands that Alice might use to generate a key and encrypt: $ java com.learnsecurity.aesencrypter createkey mykey $ echo "Meet Me At Central Park" java com.learnsecurity AESEncrypter encrypt mykey > ciphertext

2 211 Note that the generated key is stored in a file called mykey, and the encrypted text is stored in the ciphertext file. (We do not show the contents of the ciphertext file, as it is made up of nonprintable binary data, and will differ depending upon the key that is generated.) Once Alice provides the mykey file to Bob over a secure channel, she can then safely send the ciphertext file (or any other files encrypted with the same key) to Bob over an insecure channel. Once Bob receives ciphertext, he can use the AESEncrypter program to decrypt the text as follows: $ java com.learnsecurity.aesencrypter decrypt mykey < ciphertext Meet Me At Central Park The entire code for the utility is shown here: package com.learnsecurity; import java.security.*; import java.security.spec.*; import javax.crypto.*; import javax.crypto.spec.*; import java.io.*; public class AESEncrypter { public static final int IV_SIZE = 16; // 128 bits public static final int KEY_SIZE = 16; // 128 bits public static final int BUFFER_SIZE = 1024; // 1KB Cipher cipher; SecretKey secretkey; AlgorithmParameterSpec ivspec; byte[] buf = new byte[buffer_size]; byte[] ivbytes = new byte[iv_size]; public AESEncrypter(SecretKey key) throws Exception { cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); secretkey = key; public void encrypt(inputstream in, OutputStream out) throws Exception { // create IV and write to output ivbytes = createrandbytes(iv_size); out.write(ivbytes); cipher.init(cipher.encrypt_mode, secretkey, ivspec); // Bytes written to cipherout will be encrypted CipherOutputStream cipherout = new CipherOutputStream(out, cipher);

3 212 // Read in the plaintext bytes and write to cipherout to encrypt while ((numread = in.read(buf)) >= 0) cipherout.write(buf, 0, numread); cipherout.close(); public void decrypt(inputstream in, OutputStream out) throws Exception { // read IV first in.read(ivbytes); cipher.init(cipher.decrypt_mode, secretkey, ivspec); // Bytes read from in will be decrypted CipherInputStream cipherin = new CipherInputStream(in, cipher); // Read in the decrypted bytes and write the plaintext to out while ((numread = cipherin.read(buf)) >= 0) out.write(buf, 0, numread); out.close(); public static byte [] createrandbytes(int numbytes) throws NoSuchAlgorithmException { byte [] bytesbuffer = new byte [numbytes]; SecureRandom sr = SecureRandom.getInstance("SHA1PRNG"); sr.nextbytes(bytesbuffer); return bytesbuffer; public static void main(string argv[]) throws Exception { if (argv.length!= 2) String operation = argv[0]; String keyfile = argv[1]; if (operation.equals("createkey")) { FileOutputStream fos = new FileOutputStream(keyFile); KeyGenerator kg = KeyGenerator.getInstance("AES"); kg.init(key_size*8); SecretKey skey = kg.generatekey(); /* write key */ fos.write(skey.getencoded()); fos.close(); else { /* read key */

4 213 byte keybytes [] = new byte [KEY_SIZE]; FileInputStream fis = new FileInputStream(keyFile); fis.read(keybytes); SecretKeySpec keyspec = new SecretKeySpec(keyBytes, "AES"); /* initialize encrypter */ AESEncrypter aes = new AESEncrypter(keySpec); if (operation.equals("encrypt")) { aes.encrypt(system.in, System.out); else if (operation.equals("decrypt")) { aes.decrypt(system.in, System.out); else { public static void usage () { System.err.println("java com.learnsecurity.aesencrypter " + "createkey encrypt decrypt <keyfile>"); System.exit(-1); We now walk through bite-sized pieces of the code, one chunk at a time. We start with the imports and data members of the AESEncrypter class: package com.learnsecurity; import java.security.*; import java.security.spec.*; import javax.crypto.*; import javax.crypto.spec.*; import java.io.*; public class AESEncrypter { public static final int IV_SIZE = 16; // 128 bits public static final int KEY_SIZE = 16; // 128 bits public static final int BUFFER_SIZE = 1024; // 1KB Cipher cipher; SecretKey secretkey; AlgorithmParameterSpec ivspec; byte[] buf = new byte[buffer_size]; byte[] ivbytes = new byte[iv_size];

5 214 The imports at the top of the program simply declare that our program uses the Java security and cryptography support packages, in addition to the I/O library. The IV_SIZE and KEY_SIZE for our AESEncrypter class are defined to be 16 bytes, or 128 bits. BUFFER_SIZE specifies the size of the buffer that will be used to read in chunks of the input and write chunks of output. AESEncrypter uses a cipher object, defined in the Java cryptography library, that will be used to actually do the encryption or decryption, as specified by the program s command-line arguments. The secretkey object will store the secret, symmetric key that will be used. The ivspec object will specify the IV to be used to initialize the CBC. The ivspec object is initialized using bytes from ivbytes. The first line of the constructor for the AESEncrypter class initializes the cipher object to use AES in CBC mode: public AESEncrypter(SecretKey key) throws Exception { cipher = Cipher.getInstance("AES/CBC/PKCS5Padding"); secretkey = key; It also specifies that PKCS #5 padding should be used. If the input to encrypt is not, say, a multiple of 128 bits, it will be padded extra data will be added to the input to force the input to be a multiple of 128 bits. While we do not go into the details of PKCS #5 (or other padding schemes), you can read more about the topic in PKCS #5: Password-Based Cryptography Standard, by RSA Laboratories. The remaining line in the constructor simply caches the secret key in a data member of the AESEncrypter object. We describe the encrypt() and decrypt() methods next. Both of them take input and output streams as parameters. The input stream allows the method to read input from a file (or from wherever the input stream originates), and the output stream allows the method to output data. In the case of encrypt(), as you might expect, the input stream is plaintext and the output stream is ciphertext, while in the case of decrypt(), it is vice versa. The encrypt() method is as follows: public void encrypt(inputstream in, OutputStream out) throws Exception { // create IV and write to output ivbytes = createrandbytes(iv_size); out.write(ivbytes); cipher.init(cipher.encrypt_mode, secretkey, ivspec); // Bytes written to cipherout will be encrypted CipherOutputStream cipherout = new CipherOutputStream(out, cipher); // Read in the plaintext bytes and write to cipherout to encrypt while ((numread = in.read(buf)) >= 0) cipherout.write(buf, 0, numread); cipherout.close();

6 215 The encrypt() method first generates some random bytes to serve as the IV, and stores those bytes in the ivspec object. Then, the method initializes the cipher object to be in encrypt mode, and passes it the secret key and IV. The method then constructs a CipherOutputStream object from the output stream passed to encrypt() and the cipher object. Any data that is written to the CipherOutputStream object is first enciphered, and then written to the output stream. Once the CipherOutputStream object is initialized, the method then enters a loop in which data is read from the input stream and written to CipherOutputStream until all the data from the input stream has been consumed. Finally, the CipherOutputStream object is closed, and any remaining unencrypted bytes are padded, encrypted, and written. If the output stream is a file or a network socket, it will be closed. The decrypt() method is similar to the encrypt() method, except that it reads the IV and ciphertext from the input stream, and writes plaintext to the output stream: public void decrypt(inputstream in, OutputStream out) throws Exception { // read IV first in.read(ivbytes); cipher.init(cipher.decrypt_mode, secretkey, ivspec); // Bytes read from in will be decrypted CipherInputStream cipherin = new CipherInputStream(in, cipher); // Read in the decrypted bytes and write the plaintext to out while ((numread = cipherin.read(buf)) >= 0) out.write(buf, 0, numread); out.close(); Now that we have described the most important subroutines in AESEncrypter, we show how the program s main() method brings it all together: public static void main (String argv[]) throws Exception { if (argv.length!= 2) String operation = argv[0]; String keyfile = argv[1]; if (operation.equals("createkey")) { FileOutputStream fos = new FileOutputStream(keyFile); KeyGenerator kg = KeyGenerator.getInstance("AES"); kg.init(key_size*8); SecretKey skey = kg.generatekey(); /* write key */ fos.write(skey.getencoded()); fos.close(); else {

7 216 /* read key */ byte keybytes [] = new byte [KEY_SIZE]; FileInputStream fis = new FileInputStream(keyFile); fis.read(keybytes); SecretKeySpec keyspec = new SecretKeySpec(keyBytes, "AES"); /* initialize encrypter */ AESEncrypter aes = new AESEncrypter(keySpec); if (operation.equals("encrypt")) { aes.encrypt(system.in, System.out); else if (operation.equals("decrypt")) { aes.decrypt(system.in, System.out); else { The main() method first reads its two command-line arguments: the operation that the user would like to conduct, and the name of the key file. In the case that the user did not supply enough command-line arguments, a usage message is printed to the standard error output stream. Then, depending upon the operation requested, it takes an appropriate action. In the case that the user asks to create a key, the program creates a new file using a FileOutputStream object, and writes the key returned by the KeyGenerator s generatekey() method to the file. The KeyGenerator class in Java should be used to construct cryptographically random keys that are not weak (see Section 14.2 for more information about weak keys). If the user requests encryption or decryption, the main program simply calls the encrypt() or decrypt() method, respectively, after initializing the AESEncrypter object with the key read from the key file. (If the user did not specify a valid operation, a usage error is printed.) From the preceding example, you can see how it s possible to practically implement a flexible encryption tool in just a few lines of code. With just this small program, you can encrypt and decrypt any file. However, AESEncrypter does not provide integrity protection for the encrypted file, and in the real world you would add on a message authentication code (MAC) and use a key derivation function to get a different MAC and encryption key. Aside from the limitation of not automatically providing integrity protection, the AESEncrypter class is written such that it can be used in other programs to encrypt and decrypt not only files, but also any data that can be transferred over a stream, including data that is exchanged between clients and servers over network sockets. As you can imagine, one major challenge is securely distributing the key file to the client and server. In Chapters 13 and 14, we discuss asymmetric cryptography and key exchange, which helps address the key distribution problem. In this chapter, we complete our discussion of symmetric cryptography with an introduction to stream ciphers.

Information System Security

Information System Security Prof. Dr. Christoph Karg Aalen University Of Applied Sciences Department Of Computer Science Information System Security Exercise: Cryptography with Java October 16, 2017 The goal of this laboratory exercise

More information

Algunas clases e interfaces de la JCE (Java Cryptographic Extension)

Algunas clases e interfaces de la JCE (Java Cryptographic Extension) Algunas clases e interfaces de la JCE (Java Cryptographic Extension) Generación de números aleatorios: java.security.securerandom Generación de claves: java.security.key javax.crypto.secretkey javax.crypto.keygenerator

More information

ENEE 459-C Computer Security. Symmetric key encryption in practice: DES and AES algorithms

ENEE 459-C Computer Security. Symmetric key encryption in practice: DES and AES algorithms ENEE 459-C Computer Security Symmetric key encryption in practice: DES and AES algorithms A perfect encryption of a block Say you have a block of n bits You want to encrypt it You want to use the same

More information

BEng (Hons) Telecommunications. Examinations for / Semester 1

BEng (Hons) Telecommunications. Examinations for / Semester 1 BEng (Hons) Telecommunications Cohort: BTEL/14B/FT Examinations for 2017 2018 / Semester 1 MODULE: Security in Telecommunications MODULE CODE: SECU4114 Duration: 3 Hours Instructions to Candidates: 1.

More information

Introduction to Symmetric Cryptography

Introduction to Symmetric Cryptography Introduction to Symmetric Cryptography Tingting Chen Cal Poly Pomona 1 Some slides are from Dr. Cliff Zou. www.cs.ucf.edu/~czou/cis3360-12/ch08-cryptoconcepts.ppt Basic Cryptography Private Key Cryptography

More information

CS255. Programming Assignment #1

CS255. Programming Assignment #1 CS255 Programming Assignment #1 Programming Assignment #1 Due: Friday Feb 10 th (11:59pm) Can use extension days Can work in pairs One solution per pair Test and submit on Sweet Hall machines SCPD students:

More information

Mobile Security Fall 2013

Mobile Security Fall 2013 Mobile Security 14-829 Fall 2013 Yuan Tian Class #25 Security Misuse in Mobile 2013 Patrick Tague Outline Misuse of SSL in mobile development Misuse of encryption in mobile development Some slides are

More information

EUCEG: Encryption process

EUCEG: Encryption process EUROPEAN COMMISSION DIRECTORATE-GENERAL FOR HEALTH AND FOOD SAFETY General Affairs Information systems EUCEG: Encryption process Document Control Information Settings Document Title: Project Title: Document

More information

1.264 Lecture 28. Cryptography: Asymmetric keys

1.264 Lecture 28. Cryptography: Asymmetric keys 1.264 Lecture 28 Cryptography: Asymmetric keys Next class: Anderson chapters 20. Exercise due before class (Reading doesn t cover same topics as lecture) 1 Asymmetric or public key encryption Receiver

More information

L13. Reviews. Rocky K. C. Chang, April 10, 2015

L13. Reviews. Rocky K. C. Chang, April 10, 2015 L13. Reviews Rocky K. C. Chang, April 10, 2015 1 Foci of this course Understand the 3 fundamental cryptographic functions and how they are used in network security. Understand the main elements in securing

More information

CSE 127: Computer Security Cryptography. Kirill Levchenko

CSE 127: Computer Security Cryptography. Kirill Levchenko CSE 127: Computer Security Cryptography Kirill Levchenko October 24, 2017 Motivation Two parties want to communicate securely Secrecy: No one else can read messages Integrity: messages cannot be modified

More information

Cryptography. If privacy is outlawed, only outlaws will have privacy. Zimmerman (author of PGP) 1/18

Cryptography. If privacy is outlawed, only outlaws will have privacy. Zimmerman (author of PGP) 1/18 Cryptography Symmetric versus asymmetric cryptography. In symmetric the encryption and decryption keys are the same while in asymmetric cryptography they are different. Public key cryptography. (asymmetric)

More information

There are numerous Python packages for cryptography. The most widespread is maybe pycrypto, which is however unmaintained since 2015, and has

There are numerous Python packages for cryptography. The most widespread is maybe pycrypto, which is however unmaintained since 2015, and has 1 There are numerous Python packages for cryptography. The most widespread is maybe pycrypto, which is however unmaintained since 2015, and has unpatched buffer-overflow vulnerabilities. New projects should

More information

Software Interfaces to Cryptographic Primitives

Software Interfaces to Cryptographic Primitives Software Interfaces to Cryptographic Primitives Frank Piessens (Frank.Piessens@cs.kuleuven.be ) Secappdev 2007 1 Overview Introduction Cryptographic Primitives Cryptographic API s Key Management Issues

More information

Object-Oriented Programming Design. Topic : Streams and Files

Object-Oriented Programming Design. Topic : Streams and Files Electrical and Computer Engineering Object-Oriented Topic : Streams and Files Maj Joel Young Joel Young@afit.edu. 18-Sep-03 Maj Joel Young Java Input/Output Java implements input/output in terms of streams

More information

Cryptography Basics. IT443 Network Security Administration Slides courtesy of Bo Sheng

Cryptography Basics. IT443 Network Security Administration Slides courtesy of Bo Sheng Cryptography Basics IT443 Network Security Administration Slides courtesy of Bo Sheng 1 Outline Basic concepts in cryptography systems Secret key cryptography Public key cryptography Hash functions 2 Encryption/Decryption

More information

9/30/2016. Cryptography Basics. Outline. Encryption/Decryption. Cryptanalysis. Caesar Cipher. Mono-Alphabetic Ciphers

9/30/2016. Cryptography Basics. Outline. Encryption/Decryption. Cryptanalysis. Caesar Cipher. Mono-Alphabetic Ciphers Cryptography Basics IT443 Network Security Administration Slides courtesy of Bo Sheng Basic concepts in cryptography systems Secret cryptography Public cryptography 1 2 Encryption/Decryption Cryptanalysis

More information

1.264 Lecture 27. Security protocols Symmetric cryptography. Next class: Anderson chapter 10. Exercise due after class

1.264 Lecture 27. Security protocols Symmetric cryptography. Next class: Anderson chapter 10. Exercise due after class 1.264 Lecture 27 Security protocols Symmetric cryptography Next class: Anderson chapter 10. Exercise due after class 1 Exercise: hotel keys What is the protocol? What attacks are possible? Copy Cut and

More information

Network Layer, Link Layer, and Network Security Summary

Network Layer, Link Layer, and Network Security Summary CPSC 826 Internetworking, Link Layer, and Network Security Summary http://www.cs.clemson.edu/~mweigle/courses/cpsc826 1 Chapter 4, 5, 8 Topics» Forwarding and Routing» Router Architecture» Internet Protocol

More information

CRYPTOLOGY KEY MANAGEMENT CRYPTOGRAPHY CRYPTANALYSIS. Cryptanalytic. Brute-Force. Ciphertext-only Known-plaintext Chosen-plaintext Chosen-ciphertext

CRYPTOLOGY KEY MANAGEMENT CRYPTOGRAPHY CRYPTANALYSIS. Cryptanalytic. Brute-Force. Ciphertext-only Known-plaintext Chosen-plaintext Chosen-ciphertext CRYPTOLOGY CRYPTOGRAPHY KEY MANAGEMENT CRYPTANALYSIS Cryptanalytic Brute-Force Ciphertext-only Known-plaintext Chosen-plaintext Chosen-ciphertext 58 Types of Cryptographic Private key (Symmetric) Public

More information

Computer Security. 08r. Pre-exam 2 Last-minute Review Cryptography. Paul Krzyzanowski. Rutgers University. Spring 2018

Computer Security. 08r. Pre-exam 2 Last-minute Review Cryptography. Paul Krzyzanowski. Rutgers University. Spring 2018 Computer Security 08r. Pre-exam 2 Last-minute Review Cryptography Paul Krzyzanowski Rutgers University Spring 2018 March 26, 2018 CS 419 2018 Paul Krzyzanowski 1 Cryptographic Systems March 26, 2018 CS

More information

3 Symmetric Key Cryptography 3.1 Block Ciphers Symmetric key strength analysis Electronic Code Book Mode (ECB) Cipher Block Chaining Mode (CBC) Some

3 Symmetric Key Cryptography 3.1 Block Ciphers Symmetric key strength analysis Electronic Code Book Mode (ECB) Cipher Block Chaining Mode (CBC) Some 3 Symmetric Key Cryptography 3.1 Block Ciphers Symmetric key strength analysis Electronic Code Book Mode (ECB) Cipher Block Chaining Mode (CBC) Some popular block ciphers Triple DES Advanced Encryption

More information

OpenSSL is a project comprising (1) a core library and (2) a toolkit. The core library offers an API for developers of secure applications.

OpenSSL is a project comprising (1) a core library and (2) a toolkit. The core library offers an API for developers of secure applications. 1 OpenSSL is a project comprising (1) a core library and (2) a toolkit. The core library offers an API for developers of secure applications. The toolkit offers a series of command-line tools to perform

More information

Cryptographic Concepts

Cryptographic Concepts Outline Identify the different types of cryptography Learn about current cryptographic methods Chapter #23: Cryptography Understand how cryptography is applied for security Given a scenario, utilize general

More information

Cryptography Functions

Cryptography Functions Cryptography Functions Lecture 3 1/29/2013 References: Chapter 2-3 Network Security: Private Communication in a Public World, Kaufman, Perlman, Speciner Types of Cryptographic Functions Secret (Symmetric)

More information

Chapter 3 Traditional Symmetric-Key Ciphers 3.1

Chapter 3 Traditional Symmetric-Key Ciphers 3.1 Chapter 3 Traditional Symmetric-Key Ciphers 3.1 Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 3 Objectives To define the terms and the concepts of symmetric

More information

Verteilte Systeme UE Important Code

Verteilte Systeme UE Important Code Verteilte Systeme UE Important Code Lab 1 Create ServerSocket ServerSocket serversocket = new ServerSocket(tcpPort); //throws IOException Accept ClientSocket Socket clientsocket = serversocket.accept();

More information

Using block ciphers 1

Using block ciphers 1 Using block ciphers 1 Using block ciphers DES is a type of block cipher, taking 64-bit plaintexts and returning 64-bit ciphetexts. We now discuss a number of ways in which block ciphers are employed in

More information

Lecture 9a: Secure Sockets Layer (SSL) March, 2004

Lecture 9a: Secure Sockets Layer (SSL) March, 2004 Internet and Intranet Protocols and Applications Lecture 9a: Secure Sockets Layer (SSL) March, 2004 Arthur Goldberg Computer Science Department New York University artg@cs.nyu.edu Security Achieved by

More information

PROTECTING CONVERSATIONS

PROTECTING CONVERSATIONS PROTECTING CONVERSATIONS Basics of Encrypted Network Communications Naïve Conversations Captured messages could be read by anyone Cannot be sure who sent the message you are reading Basic Definitions Authentication

More information

Chapter 8. Encipherment Using Modern Symmetric-Key Ciphers

Chapter 8. Encipherment Using Modern Symmetric-Key Ciphers Chapter 8 Encipherment Using Modern Symmetric-Key Ciphers Copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 8.1 Chapter 18 Objectives To show how modern standard

More information

How many DES keys, on the average, encrypt a particular plaintext block to a particular ciphertext block?

How many DES keys, on the average, encrypt a particular plaintext block to a particular ciphertext block? Homework 1. Come up with as efficient an encoding as you can to specify a completely general one-to-one mapping between 64-bit input values and 64-bit output values. 2. Token cards display a number that

More information

Core Security Services and Bootstrapping in the Cherubim Security System

Core Security Services and Bootstrapping in the Cherubim Security System Core Security Services and Bootstrapping in the Cherubim Security System Charles Willis cfwillis@uiuc.edu Technical Report 2 July 1998 University of Illinois at Urbana-Champaign Department of Computer

More information

CSC 774 Network Security

CSC 774 Network Security CSC 774 Network Security Topic 2. Review of Cryptographic Techniques CSC 774 Dr. Peng Ning 1 Outline Encryption/Decryption Digital signatures Hash functions Pseudo random functions Key exchange/agreement/distribution

More information

Course Map. COMP 7/8120 Cryptography and Data Security. Learning Objectives. How to use PRPs (Block Ciphers)? 2/14/18

Course Map. COMP 7/8120 Cryptography and Data Security. Learning Objectives. How to use PRPs (Block Ciphers)? 2/14/18 Course Map Key Establishment Authenticated Encryption Key Management COMP 7/8120 Cryptography and Data Security Lecture 8: How to use Block Cipher - many time key Stream Ciphers Block Ciphers Secret Key

More information

The Bouncy Castle FIPS Java API in 100 Examples (Final Draft) David Hook

The Bouncy Castle FIPS Java API in 100 Examples (Final Draft) David Hook The Bouncy Castle FIPS Java API in 100 Examples (Final Draft) David Hook Copyright (c) 2016 David Hook Published by CERTOSS, Inc, 10846 Via San Marino, Cupertino, CA 95014, United States of America For

More information

Spring 2008, CSC395 Special Topics: Information Security Project 3

Spring 2008, CSC395 Special Topics: Information Security Project 3 Spring 2008, CSC395 Special Topics: Information Security Project 3 Due: March 31, 2008, 23:59. How: 1 copy in your digital drop box, and 1 copy in your Unix directory (\CSC395\Project-3). No excuse if

More information

CS61A Lecture #39: Cryptography

CS61A Lecture #39: Cryptography Announcements: CS61A Lecture #39: Cryptography Homework 13 is up: due Monday. Homework 14 will be judging the contest. HKN surveys on Friday: 7.5 bonus points for filling out their survey on Friday (yes,

More information

Block Cipher Modes of Operation

Block Cipher Modes of Operation Block Cipher Modes of Operation Luke Anderson luke@lukeanderson.com.au 23 rd March 2018 University Of Sydney Overview 1. Crypto-Bulletin 2. Modes Of Operation 2.1 Evaluating Modes 2.2 Electronic Code Book

More information

Programming Project # 1. CS255 Due: Monday, February 7 th (11:59 pm)

Programming Project # 1. CS255 Due: Monday, February 7 th (11:59 pm) Programming Project # 1 CS255 Due: Monday, February 7 th (11:59 pm) Communication 60,000 feet Arguments 60,000 feet Big idea Broker wants to broadcast hot tips But doesn t want just anyone to be able to

More information

Practical Aspects of Modern Cryptography

Practical Aspects of Modern Cryptography Practical Aspects of Modern Cryptography Lecture 3: Symmetric s and Hash Functions Josh Benaloh & Brian LaMacchia Meet Alice and Bob Alice Bob Message Modern Symmetric s Setup: Alice wants to send a private

More information

ICT 6541 Applied Cryptography. Hossen Asiful Mustafa

ICT 6541 Applied Cryptography. Hossen Asiful Mustafa ICT 6541 Applied Cryptography Hossen Asiful Mustafa Basic Communication Alice talking to Bob Alice Bob 2 Eavesdropping Eve listening the conversation Alice Bob 3 Secure Communication Eve listening the

More information

A hash function is strongly collision-free if it is computationally infeasible to find different messages M and M such that H(M) = H(M ).

A hash function is strongly collision-free if it is computationally infeasible to find different messages M and M such that H(M) = H(M ). CA4005: CRYPTOGRAPHY AND SECURITY PROTOCOLS 1 5 5.1 A hash function is an efficient function mapping binary strings of arbitrary length to binary strings of fixed length (e.g. 128 bits), called the hash-value

More information

Cryptography MIS

Cryptography MIS Cryptography MIS-5903 http://community.mis.temple.edu/mis5903sec011s17/ Cryptography History Substitution Monoalphabetic Polyalphabetic (uses multiple alphabets) uses Vigenere Table Scytale cipher (message

More information

CPSC 467: Cryptography and Computer Security

CPSC 467: Cryptography and Computer Security CPSC 467: Cryptography and Computer Security Michael J. Fischer Lecture 11 October 4, 2017 CPSC 467, Lecture 11 1/39 ElGamal Cryptosystem Message Integrity and Authenticity Message authentication codes

More information

CIS 4360 Secure Computer Systems Symmetric Cryptography

CIS 4360 Secure Computer Systems Symmetric Cryptography CIS 4360 Secure Computer Systems Symmetric Cryptography Professor Qiang Zeng Spring 2017 Previous Class Classical Cryptography Frequency analysis Never use home-made cryptography Goals of Cryptography

More information

CS 161 Computer Security

CS 161 Computer Security Raluca Popa Spring 2018 CS 161 Computer Security Homework 2 Due: Wednesday, February 14, at 11:59pm Instructions. This homework is due Wednesday, February 14, at 11:59pm. No late homeworks will be accepted.

More information

Introduction. CSE 5351: Introduction to cryptography Reading assignment: Chapter 1 of Katz & Lindell

Introduction. CSE 5351: Introduction to cryptography Reading assignment: Chapter 1 of Katz & Lindell Introduction CSE 5351: Introduction to cryptography Reading assignment: Chapter 1 of Katz & Lindell 1 Cryptography Merriam-Webster Online Dictionary: 1. secret writing 2. the enciphering and deciphering

More information

CIS 4360 Introduction to Computer Security Fall WITH ANSWERS in bold. First Midterm

CIS 4360 Introduction to Computer Security Fall WITH ANSWERS in bold. First Midterm CIS 4360 Introduction to Computer Security Fall 2010 WITH ANSWERS in bold Name:.................................... Number:............ First Midterm Instructions This is a closed-book examination. Maximum

More information

Encrypted Data Deduplication in Cloud Storage

Encrypted Data Deduplication in Cloud Storage Encrypted Data Deduplication in Cloud Storage Chun- I Fan, Shi- Yuan Huang, Wen- Che Hsu Department of Computer Science and Engineering Na>onal Sun Yat- sen University Kaohsiung, Taiwan AsiaJCIS 2015 Outline

More information

CSC 474/574 Information Systems Security

CSC 474/574 Information Systems Security CSC 474/574 Information Systems Security Topic 2.1 Introduction to Cryptography CSC 474/574 By Dr. Peng Ning 1 Cryptography Cryptography Original meaning: The art of secret writing Becoming a science that

More information

(2½ hours) Total Marks: 75

(2½ hours) Total Marks: 75 (2½ hours) Total Marks: 75 N. B.: (1) All questions are compulsory. (2) Makesuitable assumptions wherever necessary and state the assumptions made. (3) Answers to the same question must be written together.

More information

Cryptography. If privacy is outlawed, only outlaws will have privacy. Zimmerman (author of PGP)

Cryptography. If privacy is outlawed, only outlaws will have privacy. Zimmerman (author of PGP) Cryptography Symmetric versus asymmetric cryptography. In symmetric the encryption and decryption keys are the same while in asymmetric cryptography they are different. Public key cryptography. (asymmetric)

More information

Leveraging Intel SGX to Create a Nondisclosure Cryptographic library

Leveraging Intel SGX to Create a Nondisclosure Cryptographic library CS 2530 - Computer and Network Security Project presentation Leveraging Intel SGX to Create a Nondisclosure Cryptographic library Mohammad H Mofrad & Spencer L Gray University of Pittsburgh Thursday, December

More information

Symmetric Encryption

Symmetric Encryption Symmetric Encryption Ahmed Y. Banihammd & Ihsan, ALTUNDAG Mon November 5, 2007 Advanced Cryptography 1st Semester 2007-2008 University Joseph Fourrier, Verimag Master Of Information Security And Coding

More information

Waspmote Encryption Libraries. Programming guide

Waspmote Encryption Libraries. Programming guide Waspmote Encryption Libraries Programming guide Index Document version: v7.0-02/2017 Libelium Comunicaciones Distribuidas S.L. INDEX 1. Introduction... 3 2. Integrity... 6 2.1. Waspmote Libraries...6 2.1.1.

More information

CSC/ECE 774 Advanced Network Security

CSC/ECE 774 Advanced Network Security Computer Science CSC/ECE 774 Advanced Network Security Topic 2. Network Security Primitives CSC/ECE 774 Dr. Peng Ning 1 Outline Absolute basics Encryption/Decryption; Digital signatures; D-H key exchange;

More information

Computer Security Fall 2006 Joseph/Tygar MT 2 Solutions

Computer Security Fall 2006 Joseph/Tygar MT 2 Solutions CS 161 Computer Security Fall 2006 Joseph/Tygar MT 2 Solutions Problem 1. [Covert Channels] (30 points) (a) (5 points) Write down the Fiat-Shamir zero-knowledge protocol (as presented in class) where Alice

More information

Computer Security. 10r. Recitation assignment & concept review. Paul Krzyzanowski. Rutgers University. Spring 2018

Computer Security. 10r. Recitation assignment & concept review. Paul Krzyzanowski. Rutgers University. Spring 2018 Computer Security 10r. Recitation assignment & concept review Paul Krzyzanowski Rutgers University Spring 2018 April 3, 2018 CS 419 2018 Paul Krzyzanowski 1 1. What is a necessary condition for perfect

More information

borzoi Manual Dragongate Technologies Ltd.

borzoi Manual Dragongate Technologies Ltd. borzoi Manual Dragongate Technologies Ltd. September 21, 2003 Contents 1 Introduction 1 2 Preliminaries 2 2.1 Header Files............................ 2 2.2 Type Definitions......................... 2

More information

Encryption. INST 346, Section 0201 April 3, 2018

Encryption. INST 346, Section 0201 April 3, 2018 Encryption INST 346, Section 0201 April 3, 2018 Goals for Today Symmetric Key Encryption Public Key Encryption Certificate Authorities Secure Sockets Layer Simple encryption scheme substitution cipher:

More information

Refresher: Applied Cryptography

Refresher: Applied Cryptography Refresher: Applied Cryptography (emphasis on common tools for secure processors) Chris Fletcher Fall 2017, 598 CLF, UIUC Complementary reading Intel SGX Explained (ISE) Victor Costan, Srini Devadas https://eprint.iacr.org/2016/086.pdf

More information

UNIT - IV Cryptographic Hash Function 31.1

UNIT - IV Cryptographic Hash Function 31.1 UNIT - IV Cryptographic Hash Function 31.1 31-11 SECURITY SERVICES Network security can provide five services. Four of these services are related to the message exchanged using the network. The fifth service

More information

Session. Introduction to Java Cryptography API 2015, C-DAC

Session. Introduction to Java Cryptography API 2015, C-DAC Session Introduction to Java Cryptography API 2015, C-DAC Objectives To understand concepts of Java Cryptography API and other APIs in Java We Should Have Know The Keyword Plaintext. The message which

More information

Symmetric Cryptography

Symmetric Cryptography CSE 484 (Winter 2010) Symmetric Cryptography Tadayoshi Kohno Thanks to Dan Boneh, Dieter Gollmann, John Manferdelli, John Mitchell, Vitaly Shmatikov, Bennet Yee, and many others for sample slides and materials...

More information

Chapter 10. IO Streams

Chapter 10. IO Streams Chapter 10 IO Streams Java I/O The Basics Java I/O is based around the concept of a stream Ordered sequence of information (bytes) coming from a source, or going to a sink Simplest stream reads/writes

More information

CS 161 Computer Security

CS 161 Computer Security Popa & Wagner Spring 2016 CS 161 Computer Security Midterm 2 Print your name:, (last) (first) I am aware of the Berkeley Campus Code of Student Conduct and acknowledge that academic misconduct will be

More information

typedef void (*type_fp)(void); int a(char *s) { type_fp hf = (type_fp)(&happy_function); char buf[16]; strncpy(buf, s, 18); (*hf)(); return 0; }

typedef void (*type_fp)(void); int a(char *s) { type_fp hf = (type_fp)(&happy_function); char buf[16]; strncpy(buf, s, 18); (*hf)(); return 0; } Dawn Song Fall 2012 CS 161 Computer Security Practice Questions 1. (6 points) Control Hijacking Indicate whether the statement is always valid. Indicate true or false, and give a one sentence explanation.

More information

Data Integrity. Modified by: Dr. Ramzi Saifan

Data Integrity. Modified by: Dr. Ramzi Saifan Data Integrity Modified by: Dr. Ramzi Saifan Encryption/Decryption Provides message confidentiality. Does it provide message authentication? 2 Message Authentication Bob receives a message m from Alice,

More information

SECURE INTEGRATION OF CRYPTOGRAPHIC SOFTWARE

SECURE INTEGRATION OF CRYPTOGRAPHIC SOFTWARE SECURE INTEGRATION OF CRYPTOGRAPHIC SOFTWARE Speaker: Stefan Krüger Folie 1 When a Developer Uses a Crypto API Uses Electronic Codebook (ECB) Folie 2 The Average Developer is no Crypto Expert 88% of Android

More information

Winter 2011 Josh Benaloh Brian LaMacchia

Winter 2011 Josh Benaloh Brian LaMacchia Winter 2011 Josh Benaloh Brian LaMacchia Symmetric Cryptography January 20, 2011 Practical Aspects of Modern Cryptography 2 Agenda Symmetric key ciphers Stream ciphers Block ciphers Cryptographic hash

More information

05 - WLAN Encryption and Data Integrity Protocols

05 - WLAN Encryption and Data Integrity Protocols 05 - WLAN Encryption and Data Integrity Protocols Introduction 802.11i adds new encryption and data integrity methods. includes encryption algorithms to protect the data, cryptographic integrity checks

More information

Refund Selection Single Sign On

Refund Selection Single Sign On BankMobile Refund Selection Single Sign On OVERVIEW The BankMobile Refund Selection Single Sign-On (SSO) solution offers an integrated user authentication system for students to make their initial refund

More information

Feedback Week 4 - Problem Set

Feedback Week 4 - Problem Set 4/26/13 Homework Feedback Introduction to Cryptography Feedback Week 4 - Problem Set You submitted this homework on Mon 17 Dec 2012 11:40 PM GMT +0000. You got a score of 10.00 out of 10.00. Question 1

More information

Security+ Guide to Network Security Fundamentals, Third Edition. Chapter 11 Basic Cryptography

Security+ Guide to Network Security Fundamentals, Third Edition. Chapter 11 Basic Cryptography Security+ Guide to Network Security Fundamentals, Third Edition Chapter 11 Basic Cryptography Objectives Define cryptography Describe hashing List the basic symmetric cryptographic algorithms 2 Objectives

More information

Computational Security, Stream and Block Cipher Functions

Computational Security, Stream and Block Cipher Functions Computational Security, Stream and Block Cipher Functions 18 March 2019 Lecture 3 Most Slides Credits: Steve Zdancewic (UPenn) 18 March 2019 SE 425: Communication and Information Security 1 Topics for

More information

Chapter 8. Network Security. Cryptography. Need for Security. An Introduction to Cryptography 10/7/2010

Chapter 8. Network Security. Cryptography. Need for Security. An Introduction to Cryptography 10/7/2010 Cryptography Chapter 8 Network Security Introduction to Cryptography Substitution Ciphers Transposition Ciphers One-Time Pads Two Fundamental Cryptographic Principles Need for Security An Introduction

More information

More on Cryptography CS 136 Computer Security Peter Reiher January 19, 2017

More on Cryptography CS 136 Computer Security Peter Reiher January 19, 2017 More on Cryptography CS 136 Computer Security Peter Reiher January 19, 2017 Page 1 Outline Desirable characteristics of ciphers Stream and block ciphers Cryptographic modes Uses of cryptography Symmetric

More information

Cryptography (Overview)

Cryptography (Overview) Cryptography (Overview) Some history Caesar cipher, rot13 substitution ciphers, etc. Enigma (Turing) Modern secret key cryptography DES, AES Public key cryptography RSA, digital signatures Cryptography

More information

Cryptography. Intercepting Information Scenario 1. Tuesday, December 9, December 9, Wireless broadcasts information using radio signals

Cryptography. Intercepting Information Scenario 1. Tuesday, December 9, December 9, Wireless broadcasts information using radio signals Cryptography December 9, 2008 1 Intercepting Information Scenario 1 Wireless broadcasts information using radio signals Any computer on a wireless network CAN listen to any network traffic http://www.geeksquad.com/

More information

Public Key Cryptography, OpenPGP, and Enigmail. 31/5/ Geek Girls Carrffots GVA

Public Key Cryptography, OpenPGP, and Enigmail. 31/5/ Geek Girls Carrffots GVA Public Key Cryptography, OpenPGP, and Enigmail Cryptography is the art and science of transforming (encrypting) a message so only the intended recipient can read it Symmetric Cryptography shared secret

More information

Identity-Based Decryption

Identity-Based Decryption Identity-Based Decryption Daniel R. L. Brown May 30, 2011 Abstract Identity-based decryption is an alternative to identity-based encryption, in which Alice encrypts a symmetric key for Bob under a trusted

More information

Files and IO, Streams. JAVA Standard Edition

Files and IO, Streams. JAVA Standard Edition Files and IO, Streams JAVA Standard Edition Java - Files and I/O The java.io package contains nearly every class you might ever need to perform input and output (I/O) in Java. All these streams represent

More information

CS 161 Computer Security. Week of September 11, 2017: Cryptography I

CS 161 Computer Security. Week of September 11, 2017: Cryptography I Weaver Fall 2017 CS 161 Computer Security Discussion 3 Week of September 11, 2017: Cryptography I Question 1 Activity: Cryptographic security levels (20 min) Say Alice has a randomly-chosen symmetric key

More information

Information Security CS526

Information Security CS526 Information CS 526 Topic 3 Ciphers and Cipher : Stream Ciphers, Block Ciphers, Perfect Secrecy, and IND-CPA 1 Announcements HW1 is out, due on Sept 10 Start early, late policy is 3 total late days for

More information

Encryption Key Search

Encryption Key Search Encryption Key Search Chapter 5 Breaking the Cipher Encryption: To conceal passwords, credit card numbers, and other sensitive information from prying eyes while e-mail messages and Web pages traverse

More information

18-642: Cryptography

18-642: Cryptography 18-642: Cryptography 4/16/2018 Cryptography [without system integrity] is like investing in an armored car to carry money between a customer living in a cardboard box and a person doing business on a park

More information

APNIC elearning: Cryptography Basics

APNIC elearning: Cryptography Basics APNIC elearning: Cryptography Basics 27 MAY 2015 03:00 PM AEST Brisbane (UTC+10) Issue Date: Revision: Introduction Presenter Sheryl Hermoso Training Officer sheryl@apnic.net Specialties: Network Security

More information

CSC 474/574 Information Systems Security

CSC 474/574 Information Systems Security CSC 474/574 Information Systems Security Topic 2.2 Secret Key Cryptography CSC 474/574 Dr. Peng Ning 1 Agenda Generic block cipher Feistel cipher DES Modes of block ciphers Multiple encryptions Message

More information

Encrypting and Decrypting using CTR and CBC Modes in C# with BouncyCastle

Encrypting and Decrypting using CTR and CBC Modes in C# with BouncyCastle SE425: Communication and Information Security Recitation 5 Semester 2 5778 16 April 2018 Encrypting and Decrypting using CTR and CBC Modes in C# with BouncyCastle In this week s recitation we ll learn

More information

SYNOPSIS #include <openssl/des.h> des(3) OpenSSL des(3) void DES_random_key(DES_cblock *ret);

SYNOPSIS #include <openssl/des.h> des(3) OpenSSL des(3) void DES_random_key(DES_cblock *ret); NAME DES_random_key, DES_set_key, DES_key_sched, DES_set_key_checked, DES_set_key_unchecked, DES_set_odd_parity, DES_is_weak_key, DES_ecb_encrypt, DES_ecb2_encrypt, DES_ecb3_encrypt, DES_ncbc_encrypt,

More information

Ref:

Ref: Cryptography & digital signature Dec. 2013 Ref: http://cis.poly.edu/~ross/ 2 Cryptography Overview Symmetric Key Cryptography Public Key Cryptography Message integrity and digital signatures References:

More information

Darshan Institute of Engineering & Technology for Diploma Studies

Darshan Institute of Engineering & Technology for Diploma Studies Streams A stream is a sequence of data. In Java a stream is composed of bytes. In java, 3 streams are created for us automatically. 1. System.out : standard output stream 2. System.in : standard input

More information

Computer Security. 10. Exam 2 Review. Paul Krzyzanowski. Rutgers University. Spring 2017

Computer Security. 10. Exam 2 Review. Paul Krzyzanowski. Rutgers University. Spring 2017 Computer Security 10. Exam 2 Review Paul Krzyzanowski Rutgers University Spring 2017 March 23, 2018 CS 419 2017 Paul Krzyzanowski 1 Question 1(a) Suppose you come across some old text in the form GEPPQ

More information

Lecture 6: Symmetric Cryptography. CS 5430 February 21, 2018

Lecture 6: Symmetric Cryptography. CS 5430 February 21, 2018 Lecture 6: Symmetric Cryptography CS 5430 February 21, 2018 The Big Picture Thus Far Attacks are perpetrated by threats that inflict harm by exploiting vulnerabilities which are controlled by countermeasures.

More information

Distributed Systems. Lecture 14: Security. Distributed Systems 1

Distributed Systems. Lecture 14: Security. Distributed Systems 1 06-06798 Distributed Systems Lecture 14: Security Distributed Systems 1 What is security? policies and mechanisms threats and attacks Overview Security of electronic transactions secure channels authentication

More information

Week 12. Streams and File I/O. Overview of Streams and File I/O Text File I/O

Week 12. Streams and File I/O. Overview of Streams and File I/O Text File I/O Week 12 Streams and File I/O Overview of Streams and File I/O Text File I/O 1 I/O Overview I/O = Input/Output In this context it is input to and output from programs Input can be from keyboard or a file

More information

Java Based E-Commerce Middleware

Java Based E-Commerce Middleware Java Based E-Commerce Middleware Sub Ramakrishnan Department of Computer Science Bowling Green State University Bowling Green, OH 43403-0214 Abstract Organizations that sell products over the Internet

More information

Outline. Data Encryption Standard. Symmetric-Key Algorithms. Lecture 4

Outline. Data Encryption Standard. Symmetric-Key Algorithms. Lecture 4 EEC 693/793 Special Topics in Electrical Engineering Secure and Dependable Computing Lecture 4 Department of Electrical and Computer Engineering Cleveland State University wenbing@ieee.org Outline Review

More information

Distributed Systems. Lecture 14: Security. 5 March,

Distributed Systems. Lecture 14: Security. 5 March, 06-06798 Distributed Systems Lecture 14: Security 5 March, 2002 1 What is security? policies and mechanisms threats and attacks Overview Security of electronic transactions secure channels authentication

More information