Top Banner

Click here to load reader

Security

Nov 03, 2014

ReportDownload

Documents

priyeshb13

msc p2 com sci

Information & System Security AND Network & Internet Security

INDEXSR. NO. 1 PRACTICAL NAME PG NO. SIGN DATE

Symmetric Key Cryptography

04 10

2

Asymmetric Key Cryptography

11 17

3

Simple Cryptography

18 22

4

Caesar Cipher

23 25

5

String Encryption using a Pass Phrase

26 31

6

String Encryption using Secret Key

32 35

7

AES String Encryption and Decryption

36 39

8

AES File Encryption and Decryption

40 44

9

RSA Algorithm

45 48

10

Login Authentication

49 50

11

Message Digest

51 56

12

Exporting and Importing Keys

57 60

13

Hash Functions: RSHash, JSHash, PJWHash

61 65

Page | 1

Information & System Security AND Network & Internet Security

14

Hash Functions: ELFHash, BKDRHash, SDBMHash

66 69

15

Hash Functions: DJBHash, APHash

70 72

16

Permissions

73 77

Page | 2

Information & System Security AND Network & Internet Security

Frequently Used Terms in Security and Cryptography Security In the computer industry, SECURITY refers to techniques for ensuring that data stored in a computer cannot be read or compromised by any individuals without authorization. Most security measures involve data encryption and passwords. Data encryption is the translation of data into a form that is unintelligible without a deciphering mechanism. A password is a secret word or phrase that gives a user access to a particular program or system. Cryptography The art of protecting information by transforming it (encrypting it) into cipher text. Only those who possess a secret key can decipher (or decrypt) the message into plain text. Encrypted messages can sometimes be broken by cryptanalysis, also called codebreaking, although modern cryptography techniques are virtually unbreakable. Plain Text refers to any message that is not encrypted. Plain text is also called clear text.

Cipher Text is the data that has been encrypted or encoded. Cipher text is unreadable until it has been converted into plain text (decrypted) with a key Encryption is the translation of data into a secret code. Encryption is the most effective way to achieve data security. To read an encrypted file, you must have access to a secret key or password that enables you to decrypt it. Unencrypted data is called plain text Encrypted data is referred to as cipher text. There are two main types of encryption:

Asymmetric encryption (also called public-key encryption) Symmetric encryption.Asymmetric Key Encryption is a cryptographic system that uses two keys a public key known to everyone and a private or secret key known only to the recipient of the message. Symmetric Key Encryption is a type of encryption where the same key is used to encrypt and decrypt the message. This differs from asymmetric (or public-key) encryption, which uses one key to encrypt a message and another to decrypt the message. Decryption is the process of decoding data that has been encrypted into a secret format. Decryption requires a secret key or password.

Page | 3

Information & System Security AND Network & Internet Security

Practical No.:1 Topic: Symmetric Key Cryptography Aim: Write a program to generate Symmetric Keys of DES, AES, Blowfish, TripleDES, HmacMD5, HmacSHA1. Description: Private Key or Symmetric Key Encryption Private Key Encryption also referred to as conventional, single-key or symmetric encryption was the only available option prior to the advent of Public Key encryption in 1976. This form of encryption has been used throughout history by Julius Caesar, the Navaho Indians, German U-Boat commanders to present day military, government and private sector applications. It is an encryption system in which the sender and receiver of a message share a single, common key that is used to encrypt and decrypt the message. A conventional encryption scheme has five major parts: o o o o o Plaintext - this is the text message to which an algorithm is applied. Encryption Algorithm - it performs mathematical operations to conduct substitutions and transformations to the plaintext. Secret Key - This is the input for the algorithm as the key dictates the encrypted outcome. Ciphertext - This is the encrypted or scrambled message produced by applying the algorithm to the plaintext message using the secret key. Decryption Algorithm - This is the encryption algorithm in reverse. It uses the ciphertext, and the secret key to derive the plaintext message. The most popular symmetric-key system is the Data Encryption Standard (DES),

Advanced Encryption Standard (AES), Blowfish, Triple DES, HmacMD5 etc. Cipher Algorithms/Encryption Algorithms: Its a mathematical procedure for performing encryption on data. Through the use of an algorithm, information is made into meaningless cipher

Page | 4

Information & System Security AND Network & Internet Security

text and requires the use of a key to transform the data back into its original form. Blowfish, AES RC4, RC5, and RC6 are examples of encryption algorithms. Advanced Encryption Standard (AES): Its a symmetric 128-bit block data encryption technique developed by Belgian cryptographers Joan Daemen and Vincent Rijmen. Data Encryption Standard, (DES): Its a popular symmetric-key encryption method developed in 1975 and standardized by ANSI in 1981 as ANSI X.3.92. DES uses a 56-bit key and uses the block cipher method, which breaks text into 64-bit blocks and then encrypts them. Triple DES: Its a mode of the DES encryption algorithm that encrypts data three times. Three 64-bit keys are used, instead of one, for an overall key length of 192 bits (the first encryption is encrypted with second key, and the resulting cipher text is again encrypted with a third key). BlowFish: Its a symmetric encryption algorithm designed by Bruce Schneier in 1993 as an alternative to existing encryption algorithms, such as DES. Blowfish is a 64-bit block cipher (i.e., a cryptographic key and algorithm are applied to a block of data rather than single bits) that uses a key length that can vary between 32 and 448 bits. Used Class / Interface Details: 1) Class Name: KeyGenerator o o Package: javax.crypto: Info: This class provides the functionality of a (symmetric) key generator. Class Name: SecretKeySpec o Package: javax.crypto.spec.SecretKeySpec Info: This class specifies a secret key in a provider-independent

o

fashion. It can be used to construct a SecretKey from a byte array. 3) o o Interface Name: SecretKey Info: Its only purpose is to group (and provide type safety for) secret keys.

Package: javax.crypto:

Page | 5

Information & System Security AND Network & Internet Security

Source Code: import javax.crypto.*; import javax.crypto.spec.SecretKeySpec; class AlgoSpecificKeyGeneraor { String encryptAlgo; KeyGenerator keyGen; SecretKey secKey1, secKey2; AlgoSpecificKeyGeneraor() { this.encryptAlgo = "NULL"; } void setEncryptAlgo(String encryptAlgo) { this.encryptAlgo = encryptAlgo; } String getEncryptAlgo() { return encryptAlgo; } void generateSymmetricKeys() { try{ keyGen = KeyGenerator.getInstance(encryptAlgo); // a static method from KeyGenerator class secKey1 = keyGen.generateKey(); // Generates a 1st secret key. /* Display encryption algo */ System.out.println("Encryption Algorithm: : " + keyGen.getAlgorithm()); /* Display generated key */ System.out.println("Generated Secret Key : " + secKey1); /* Display provider */

Page | 6

Information & System Security AND Network & Internet Security

System.out.println("Provider of KeyGenerator Object : " + keyGen.getProvider()); byte[] keyBytes = secKey1.getEncoded(); // generating Key Bytes /* Constructs a 2nd secret key from the given byte array. */ secKey2 = new SecretKeySpec(keyBytes, encryptAlgo); System.out.println("Newly generated Secret Key : " + secKey2); /* Checking for the equality of both secret keys */ System.out.println("Both the Generated Symmetric Keys are equal (true/false) : " + secKey1.equals(secKey2)); }catch(Exception e){ System.err.println(e); } } } class GenerateSymKeys { public static void main(String[] args) { AlgoSpecificKeyGeneraor algoSpecificKeyGenerator = new AlgoSpecificKeyGeneraor(); /* Blowfish */ algoSpecificKeyGenerator.setEncryptAlgo("Blowfish"); System.out.println("\n(*) " + algoSpecificKeyGenerator.getEncryptAlgo() + " Details\n"); algoSpecificKeyGenerator.generateSymmetricKeys(); /* DES */ algoSpecificKeyGenerator.setEncryptAlgo("DES"); System.out.println("\n(*) " + algoSpecificKeyGenerator.getEncryptAlgo() + " Details\n"); algoSpecificKeyGenerator.generateSymmetricKeys(); /* AES */ algoSpecificKeyGenerator.setEncryptAlgo("AES"); System.out.println("\n(*) " + algoSpecificKeyGenerator.getEncryptAlgo() + " Details\n"); algoSpecificKeyGenerator.generateSymmetricKeys();

Page | 7

Information & System Security AND Network & Internet Security

/* DESede: Triple DES Encryption (DES-EDE). */ algoSpecificKeyGenerator.setEncryptAlgo("DESede"); System.out.println("\n(*) " + algoSpecificKeyGenerator.getEncryptAlgo() + " Details\n"); algoSpecificKeyGenerator.generateSymmetricKeys(); /* HmacMD5 */ algoSpecificKeyGenerator.setEncryptAlgo("HmacMD5"); System.out.println("\n(*) " + algoSpecificKeyGenerator.getEncryptAlgo() + " Details\n"); algoSpecificKeyGenerator.generateSymmetricKeys(); /* HmacSHA 1 */ algoSpecificKeyGenerator.setEncryptAlgo("HmacSHA1"); System.out.println("\n(*) " + algoSpecificKeyGenerator.getEncryptAlgo() + " Details\n"); algoSpecificKeyGenerator.ge