AES Encryption and Decryption in Microsoft.NET

Similar documents
Block Ciphers Security of block ciphers. Symmetric Ciphers

4. Design Principles of Block Ciphers and Differential Attacks

Random Bit Generation and Stream Ciphers

Lecture 1: Introduction

CDMA Physical Layer Built-in Security Enhancement

Chapter 4 The Data Encryption Standard

Network Security: Secret Key Cryptography

Cryptography. Module in Autumn Term 2016 University of Birmingham. Lecturers: Mark D. Ryan and David Galindo

V.Sorge/E.Ritter, Handout 2

Cryptography CS 555. Topic 20: Other Public Key Encryption Schemes. CS555 Topic 20 1

Pseudorandom Number Generation and Stream Ciphers

Public Key Cryptography Great Ideas in Theoretical Computer Science Saarland University, Summer 2014

DES Data Encryption standard

A Novel Encryption System using Layered Cellular Automata

Introduction to Cryptography CS 355

Proceedings of Meetings on Acoustics

Triple-DES Block of 96 Bits: An Application to. Colour Image Encryption

Merkle s Puzzles. c Eli Biham - May 3, Merkle s Puzzles (8)

Quality of Encryption Measurement of Bitmap Images with RC6, MRC6, and Rijndael Block Cipher Algorithms

CPSC 467: Cryptography and Computer Security

Solution: Alice tosses a coin and conveys the result to Bob. Problem: Alice can choose any result.

II. RC4 Cryptography is the art of communication protection. This art is scrambling a message so it cannot be clear; it

Secret Key Systems (block encoding) Encrypting a small block of text (say 128 bits) General considerations for cipher design:

Amalgamation of Cyclic Bit Operation in SD-EI Image Encryption Method: An Advanced Version of SD-EI Method: SD-EI Ver-2

DUBLIN CITY UNIVERSITY

Journal of Discrete Mathematical Sciences & Cryptography Vol. ( ), No., pp. 1 10

Secure Function Evaluation

o Broken by using frequency analysis o XOR is a polyalphabetic cipher in binary

Design of a High Throughput 128-bit AES (Rijndael Block Cipher)

Generation of AES Key Dependent S-Boxes using RC4 Algorithm

The number theory behind cryptography

Design of Message Authentication Code with AES and. SHA-1 on FPGA

Number Theory and Public Key Cryptography Kathryn Sommers

Towards a Cryptanalysis of Scrambled Spectral-Phase Encoded OCDMA

Image Encryption Based on the Modified Triple- DES Cryptosystem

A Steganography Algorithm for Hiding Secret Message inside Image using Random Key

SHA-3 and permutation-based cryptography

Lecture Notes in Computer Science Edited by G. Goos, J. Hartmanis and J. van Leeuwen

SOME OBSERVATIONS ON AES AND MINI AES. Hüseyin Demirci TÜBİTAK UEKAE

Vernam Encypted Text in End of File Hiding Steganography Technique

Diffie-Hellman key-exchange protocol

Dynamic Collage Steganography on Images

OFDM Based Low Power Secured Communication using AES with Vedic Mathematics Technique for Military Applications

TMA4155 Cryptography, Intro

Halftone based Secret Sharing Visual Cryptographic Scheme for Color Image using Bit Analysis

Minimum key length for cryptographic security

Secure Distributed Computation on Private Inputs

Keywords: dynamic P-Box and S-box, modular calculations, prime numbers, key encryption, code breaking.

Webpage: Volume 4, Issue VI, June 2016 ISSN

Chapter 4 MASK Encryption: Results with Image Analysis

Comparison of Visual Cryptographic Algorithms for Quality Images Using XOR

New High Capacity Secure Steganography Technique

High-Capacity Reversible Data Hiding in Encrypted Images using MSB Prediction

DATA SECURITY USING ADVANCED ENCRYPTION STANDARD (AES) IN RECONFIGURABLE HARDWARE FOR SDR BASED WIRELESS SYSTEMS

Classical Cryptography

Lecture 32. Handout or Document Camera or Class Exercise. Which of the following is equal to [53] [5] 1 in Z 7? (Do not use a calculator.

IND-CCA Secure Hybrid Encryption from QC-MDPC Niederreiter

High Diffusion Cipher: Encryption and Error Correction in a Single Cryptographic Primitive

Symmetric-key encryption scheme based on the strong generating sets of permutation groups

Mathematics Explorers Club Fall 2012 Number Theory and Cryptography

Prevention of Selective Jamming Attack Using Cryptographic Packet Hiding Methods

Colored Image Ciphering with Key Image

Robust Key Establishment in Sensor Networks

Quasi group based crypto-system

An Efficient Quasigroup Block Cipher

A STENO HIDING USING CAMOUFLAGE BASED VISUAL CRYPTOGRAPHY SCHEME

Dr. V.U.K.Sastry Professor (CSE Dept), Dean (R&D) SreeNidhi Institute of Science & Technology, SNIST Hyderabad, India. P = [ p

LOSSLESS CRYPTO-DATA HIDING IN MEDICAL IMAGES WITHOUT INCREASING THE ORIGINAL IMAGE SIZE THE METHOD

Cryptography, Number Theory, and RSA

EE 418: Network Security and Cryptography

Discrete Mathematics & Mathematical Reasoning Multiplicative Inverses and Some Cryptography

CRYPTANALYSIS OF THE PERMUTATION CIPHER OVER COMPOSITION MAPPINGS OF BLOCK CIPHER

Encryption at the Speed of Light? Towards a cryptanalysis of an optical CDMA encryption scheme

A New Compression Method for Encrypted Images

Course Business. Harry. Hagrid. Homework 2 Due Now. Midterm is on March 1. Final Exam is Monday, May 1 (7 PM) Location: Right here

Interleaving And Channel Encoding Of Data Packets In Wireless Communications

B. Substitution Ciphers, continued. 3. Polyalphabetic: Use multiple maps from the plaintext alphabet to the ciphertext alphabet.

Chapter 3 LEAST SIGNIFICANT BIT STEGANOGRAPHY TECHNIQUE FOR HIDING COMPRESSED ENCRYPTED DATA USING VARIOUS FILE FORMATS

Using the IFR 2975 for Advanced Project 25 Keyloading Capabilities and AES/DES Encryption

Image Encryption with Dynamic Chaotic Look-Up Table

Design and Implementation of Game Based Security Model to Secure the Information Contents

A basic guitar is a musical string instrument with six strings. In standard tuning they have the notes E, A, D, G, B and E

Cryptography Made Easy. Stuart Reges Principal Lecturer University of Washington

Introduction to Cryptography

Image Encryption Based on New One-Dimensional Chaotic Map

ElGamal Public-Key Encryption and Signature

Reversible Data Hiding in Encrypted Images based on MSB. Prediction and Huffman Coding

IMPROVED LSB BASED IMAGE STEGANOGRAPHY USING RUN LENGTH ENCODING AND RANDOM INSERTION TECHNIQUE FOR COLOR IMAGES

COS433/Math 473: Cryptography. Mark Zhandry Princeton University Spring 2017

ISSN Vol.06,Issue.09, October-2014, Pages:

CESEL: Flexible Crypto Acceleration. Kevin Kiningham Dan Boneh, Mark Horowitz, Philip Levis

Chaotically Modulated RSA/SHIFT Secured IFFT/FFT Based OFDM Wireless System

JOINT BINARY CODE COMPRESSION AND ENCRYPTION

A Novel Color Image Cryptosystem Using Chaotic Cat and Chebyshev Map

Generic Attacks on Feistel Schemes

International Journal of Advance Engineering and Research Development IMAGE BASED STEGANOGRAPHY REVIEW OF LSB AND HASH-LSB TECHNIQUES

Endurance R/C Wi-Fi Servo Controller 2 Instructions

DIY Pencil-and-Paper Encryption

Visual Cryptography Scheme for Gray Scale Images based on Intensity Division

Successful Implementation of the Hill and Magic Square Ciphers: A New Direction

Transcription:

AES Encryption and Decryption in Microsoft.NET William J. Buchanan Centre for Distributed Computing and Security, Edinburgh Napier University {w.buchanan}@napier.ac.uk http://cdcs.napier.ac.uk Abstract. This paper outlines the usage of AES in Microsoft.NET. It provides a basic overview of the AES method, along with a review of other popular encryption methods and some sample code which can be used to implement AES. 1 Introduction The future of the Internet, especially in expanding the range of applications, involves a much deeper degree of privacy, and authentication. Without these the Internet cannot be properly used to replace existing applications such as in voting, finance, and so on [3][2][1]. The future is thus towards data encryption which is the science of cryptographics, and provides a mechanism for two entities to communicate without any other entity being able to read their messages. In a secret communications system, Bob and Alice should be able to communicate securely, without Eve finding out the contents of their messages, or in keeping other details secure, such as their location, or the date that their messages are sent (Figure 1). There are many ways that encryption can be used in modern application, including encrypting data buckets in an e-health Cloud [6], in digital forensics [7] and in information sharing [9]. New methods have also been created related to new ways to encrypting data using cumulative encryption [8], which supports the usage of the encryption keys being added to the data so that it does not matter the one round that the ciper text is decrypted. For example if Alice encrypts with her key, and the Bob encrypts with his, then Alice or Bob can then apply their keys in any order, so that the data can be decrypted. The two main methods used are to either use a unique algorithm which both Bob and Alice know, and do not tell Eve, or they use a well-known algorithm, which Eve also knows, and use some special electronic key to uniquely define how the message is converted into cipertext, and back again. A particular problem in any type of encryption is the passing of the secret algorithm or the key in a secure way, as Bob or Alice does not know if Eve is listening to their communications. If Eve finds-out the algorithm or the key, neither Bob nor Alice is able to detect this. This chapter looks at some of the basic principles of encryption, including

2 William J. Buchanan the usage of private-key and public-key methods. As we will find public and private key methods work together in perfect harmony, with, typically, private key methods providing in the actual core encryption, and public key methods providing ways to authenticate, and pass keys. Fig. 1. Figure 1: Private key encryption 2 Private Key Private-key (or secret-key) encryption techniques use a secret key which is only known by the two communicating parties, as illustrated in Figure 2 [5]. This key can generated by a phase-phase, or can be passed from the two parties over a secure communications link. The most popular private-key techniques include: DES (Data Encryption Standard) is a block cipher scheme which operates on 64-bit block sizes. The private key has only 56 useful bits, as eight of its bits are used for parity (which gives 2 56 or 10 17 possible keys). DES uses a complex series of permutations and substitutions, the result of these operations is XOR ed with the input. This is then repeated 16 times using a different order of the key bits each time. DES is a strong code and has never been broken, although several high-powered computers are now available which, using brute force, can crack the code. A possible solution is 3DES (or triple DES) which uses DES three times in a row. First to encrypt, next to decrypt and finally to encrypt. This system allows a key-length of more than 128 bits. The technique uses two keys and three executions of the DES algorithm. A key, K1, is used in the first execution, then K2 is used and

AES Encryption in Microsoft.NET 3 finally K1 is used again. These two keys give an effective key length of 112 bits, that is 2 64 key bits minus 16 parity bits. The Triple DES process is illustrated in Figure 3. RC4. RC4 is a stream cipher designed by RSA Data Security, Inc and was a secret until information on it appeared on the Internet. The secure socket layer (SSL) protocol and wireless communications (IEEE 802.11a/b/g) use RC4. It uses a pseudo random number generator, where the output of the generator is XOR ed with the plaintext. It is a fast algorithm and can use any key-length. Unfortunately the same key cannot be used twice. Recently a 40-bit key version was broken in eight days without special computer power. AES/Rijndael. AES (Advanced Encryption Standard) is a new standard for encryption, and uses 128, 192 or 256 bits. It was selected by NIST in 2001 (after a five year standardisation process). The name Rijndael comes from its Belgium creators: Joan Daemen and Vincent Rijmen. The future of wireless systems (WPA-2) is likely to be based around AES (while WPA uses TKIP which is a session key method which is based around stream encryption using RC4). IDEA. IDEA (International Data Encryption Algorithm) is similar to DES. It operates on 64-bit blocks of plaintext, using a 128-bit key, and has over 17 rounds with a complicated mangler function. During decryption this function does not have to be reversed and can simply be applied in the same way as during encryption (this also occurs with DES). IDEA uses a different key expansion for encryption and decryption, but every other part of the process is identical. The same keys are used in DES decryption, but in the reverse order. The key is devised in eight 16-bit blocks; the first six are used in the first round of encryption the last two are used in the second run. It is free for use in non-commercial version and appears to be a strong cipher. RC5. RC5 is a fast block cipher designed by Rivest for RSA Data Security. It has a parameterized algorithm with a variable block size (32, 64 or 128 bits), a variable key size (0 to 2048 bits) and a variable number of rounds (0 to 255). It has a heavy use of data dependent rotations, and the mixture of different operations, which assures that RC5 is secure. The major advantage that private-key encryption has over public-key is that it is typically much faster to decrypt, and can thus be used where a fast conversion is required, such as in real-time encryption. 3 Coding AES (or Rijndael) is the new replacement for DES, and uses 128-bit blocks with 128, 192 and 256 bit encryption keys. It was selected by NIST in 2001 (after a five year standardisation process). The name Rijndael comes from its Belgium creators: Joan Daemen and Vincent Rijmen. The key has an IV and a key element, where the IV gives the overall key some variation. In this case the key is 256 bits, and the IV is 128 bits. The following defines the code used to implement AES using Microsoft.NET [4].

4 William J. Buchanan Fig. 2. Figure 2: Private key encryption Listing 1.1. 3DES Code. 1 using System ; 2 using System. Data ; 3 using System. C o n f i g u r a t i o n ; 4 using System.Web; 5 using System.Web. S e c u r i t y ; 6 using System.Web. UI ; 7 using System.Web. UI. WebControls ; 8 using System.Web. UI. WebControls. WebParts ; 9 using System.Web. UI. HtmlControls ; 10 using System. C o l l e c t i o n s ; 11 using System. S e c u r i t y. Cryptography ; 12 using System. IO ; 13 using System. Text ; 14 15 p u b l i c p a r t i a l c l a s s D e f a u l t 5 : System.Web. UI. Page 16 { 17 p r o t e c t e d void Page Load ( o b j e c t sender, EventArgs e ) 18 { 19 } 20 p r o t e c t e d void Button3 Click ( o b j e c t sender, EventArgs e ) 21 { 22 try 23 { 24 R i j n d a e l myrijndael = new RijndaelManaged ( ) ;

AES Encryption in Microsoft.NET 5 25 26 27 myrijndael. Key = StringToByte ( t h i s. tbkey. Text, 32) ; // convert to 32 c h a r a c t e r s 256 b i t s 28 myrijndael. IV = StringToByte ( 0123456789 ABCDEF ) ; // 16 chars f o r IV 29 30 byte [ ] key = myrijndael. Key ; 31 byte [ ] IV = myrijndael. IV ; 32 33 ICryptoTransform encryptor = myrijndael. CreateEncryptor ( key, IV ) ; 34 35 MemoryStream msencrypt = new MemoryStream ( ) ; 36 CryptoStream csencrypt = new CryptoStream ( msencrypt, encryptor, CryptoStreamMode. Write ) ; 37 38 // Write a l l data to t he c r y p t o stream and f l u s h i t. 39 csencrypt. Write ( StringToByte ( t h i s. tbmessage. Text ), 0, StringToByte ( t h i s. tbmessage. Text ). Length ) ; 40 csencrypt. FlushFinalBlock ( ) ; 41 42 // Get the encrypted array o f b y t e s. 43 byte [ ] encrypted = msencrypt. ToArray ( ) ; 44 45 t h i s. tbencrypt. Text = ByteToString ( encrypted ) ; 46 47 ICryptoTransform decryptor = myrijndael. CreateDecryptor ( key, IV ) ; 48 49 // Now d e c r y p t t he p r e v i o u s l y encrypted message using the d e c r y p t o r 50 MemoryStream msdecrypt = new MemoryStream ( encrypted ) ; 51 CryptoStream csdecrypt = new CryptoStream ( msdecrypt, decryptor, CryptoStreamMode. Read ) ; 52 53 t h i s. tbdecrypt. Text = ByteToString ( csdecrypt ) ;

6 William J. Buchanan 54 } 55 catch ( Exception ex ) 56 { 57 t h i s. tbencrypt. Text = ex. Message. ToString ( ) ; 58 } 59 60 } 61 p u b l i c static byte [ ] StringToByte ( s t r i n g StringToConvert ) 62 { 63 64 char [ ] CharArray = StringToConvert. ToCharArray ( ) ; 65 byte [ ] ByteArray = new byte [ CharArray. Length ] ; 66 for ( int i = 0 ; i < CharArray. Length ; i ++) 67 { 68 ByteArray [ i ] = Convert. ToByte ( CharArray [ i ] ) ; 69 } 70 return ByteArray ; 71 } 72 p u b l i c static byte [ ] StringToByte ( s t r i n g StringToConvert, int l e n g t h ) 73 { 74 75 char [ ] CharArray = StringToConvert. ToCharArray ( ) ; 76 byte [ ] ByteArray = new byte [ l e n g t h ] ; 77 for ( int i = 0 ; i < CharArray. Length ; i ++) 78 { 79 ByteArray [ i ] = Convert. ToByte ( CharArray [ i ] ) ; 80 } 81 return ByteArray ; 82 } 83 p u b l i c static s t r i n g ByteToString ( CryptoStream b u f f ) 84 { 85 s t r i n g sbinary = ; 86 int b = 0 ; 87 do 88 { 89 b = b u f f. ReadByte ( ) ; 90 i f ( b!= 1) sbinary += ( ( char ) b ) ; 91 92 } while ( b!= 1) ; 93 return ( sbinary ) ; 94 } 95 p u b l i c static s t r i n g ByteToString ( byte [ ] b u f f ) 96 {

AES Encryption in Microsoft.NET 7 97 s t r i n g sbinary = ; 98 for ( int i = 0 ; i < b u f f. Length ; i ++) 99 { 100 sbinary += b u f f [ i ]. ToString ( X2 ) ; // hex format 101 } 102 return ( sbinary ) ; 103 } 104 } 4 Testing In this case, if we try test as the key, and test message of: This is a test message which should get: 54A6B8A846B61EFBFD258AF2B1E7BF129A24545CAEDC315DA1D3F924E4AA2F00 Also, a key of test with a message of test gives: AECC52950EFC49F6B2B2407ECEE65FE5 which is 32 characters, and thus relates to 128 bits, which is the block size (as test fits into a single block). All our outputs will thus be a multiple of 32 hex characters. References 1. William J Buchanan. Distributed Systems And Networks. McGraw-Hill Higher Education, 2001. 2. William J Buchanan. The complete handbook of the Internet. Springer, 2002. 3. William J Buchanan. Handbook of Data Communications and Networks. Kluwer Academic Publishers, 2005. 4. William J Buchanan. Aes encryption in.net. http://buchananweb.co.uk/ security15.aspx, April 2011. 5. William J Buchanan. Security and forensic computing: Encryption. http:// buchananweb.co.uk/index_sfc_napier.html, March 2011. 6. L Fan, W Buchanan, C. Thuemmler, O. Lo, A. Khedim, Uthmani O., A. Lawson, and D. Bell. Dacar platform for ehealth services cloud. IEEE Cloud 2011, 2011. 7. Z. Kwecka, W. Buchanan, and D. Spiers. Minimising collateral damage: Privacypreserving investigative data acquisition platform. International Journal of Information Technologies and Systems Approach (IJITSA) : Special issue on Privacy and Security Issues in IT, 4(2), 2010. 8. Z. Kwecka, W. Buchanan, and D. Spiers. Privacy-preserving data acquisition protocol. IEEE International Conference of Computational Methods in Electrical and Electronics Engineering, pages 131 136, 2010. 9. O. Uthmani, W. Buchanan, A. Lawson, and L. Fan. Novel information sharing syntax for data sharing between police and community partners, using role-based security. Proceedings of the 9th European Conference on Information Warfare and Security, pages 394 402, 2010.