IJCSNS Intrnational Journal of Computr Scinc and Ntwork Scurity, VOL.13 No.7, July 2013 9 Data Encryption and Dcryption Using RSA Algorithm in a Ntwork Environmnt Nntaw Y. Goshw. Dpartmnt of Elctrical/Elctronics Enginring Univrsity of Agricultur, Makurdi Abstract On of th principal challngs of rsourc sharing on data communication ntwork is its scurity. This is prmisd on th fact that onc thr is connctivity btwn computrs sharing som rsourcs, th issu of data scurity bcoms critical. This papr prsnts a dsign of data ncryption and dcryption in a ntwork nvironmnt using RSA algorithm with a spcific mssag block siz. Th algorithm allows a mssag sndr to gnrat a public kys to ncrypt th mssag and th rcivr is snt a gnratd privat ky using a scurd databas. An incorrct privat ky will still dcrypt th ncryptd mssag but to a form diffrnt from th original mssag. Ky words: ncryption, dcryption, ky, Java 1. Introduction Cryptography is playing a major rol in data protction in applications running in a ntwork nvironmnt. It allows popl to do businss lctronically without worris of dcit and dcption in addition to nsuring th intgrity of th mssag and authnticity of th sndr. It has bcom mor critical to our day-to-day lif bcaus thousands of popl intract lctronically vry day; through -mail, -commrc, ATM machins, cllular phons, tc. This gomtric incras of information transmittd lctronically has mad incrasd rlianc on cryptography and authntication by usrs [1-4]. Dspit th fact that scurd communication has xistd for cnturis, th ky managmnt problm has prvntd it from commonplac application. Th dvlopmnt of public-ky cryptography has nabld larg-scal ntwork of usrs that can communicat scurly with on anothr vn if thy had nvr communicatd bfor [6-8]. This papr considrs a Public Ky ncryption mthod using RSA algorithm that will convrt th information to a form not undrstandabl by th intrudr thrfor protcting unauthorizd usrs from having accss to th information vn if thy ar abl to brak into th systm. 2. Mthodology Thr ar many ways of classifying data cryptographic algorithms but for th purpos of this papr, thy will b classifid basd on th numbr of kys that ar mployd for ncryption and dcryption. Th thr common typs of algorithms ar: a. Scrt Ky Cryptography (SKC): Th SKC mthod uss only a singl ky for both ncryption and dcryption. Th schms ar gnrally catgorizd as bing ithr stram ciphrs or block ciphrs. Stram ciphrs oprat on a singl bit (byt or computr word) at a tim and implmnt som form of fdback mchanism so that th ky is constantly changing whil block ciphr schm ncrypts on block of data at a tim using th sam ky on ach block. Th main drawback of this mthod is propagation rror bcaus a distortd bit in transmission will rsult in n distortd bits at th rciving sid. Though stram ciphrs do not propagat transmission rrors, thy ar priodic thrfor th ky-stram will vntually rpat. This normally rsults in th us of digital signatur mchanisms with ithr larg kys for th public vrification function or th us of a TTP. b. Public Ky Cryptography (PKC): PKC schm uss on ky for ncryption and a diffrnt ky for dcryption. Modrn PKC was first dscribd using a two-ky crypto systm in which two partis could ngag in a scur communication ovr a non-scur communications channl without having to shar a scrt ky [5]. In PKC, on of th kys is dsignatd th public ky and may b advrtisd as widly as th ownr wants. Th othr ky is dsignatd th privat ky and is nvr rvald to anothr party. RSA is on of th first and still most common PKC implmntation that is in us today for ky xchang or digital signaturs. Th cardinal advantag of this mthod is that administration of kys on a ntwork rquirs th prsnc of only a functionally trustd TTP, as opposd to an unconditionally trustd TTP. Dpnding on th mod of usag, th TTP might only b rquird in an off-lin mannr, as opposd to in ral tim. Many public-ky schms yild rlativly fficint signatur mchanisms. Th ky usd to dscrib th public vrification function is Manuscript rcivd July 5, 2013 Manuscript rvisd July 20, 2013
10 IJCSNS Intrnational Journal of Computr Scinc and Ntwork Scurity, VOL.13 No.7, July 2013 typically much smallr than for th symmtric-ky countrpart [6-9] c. Hash Functions (HF): Th HF uss a mathmatical transformation to irrvrsibly "ncrypt" information. This algorithm dos not us kys for ncryption and dcryption of data. It rathr uss a fixd-lngth hash valu which computd basd on a plaintxt that maks it impossibl for ithr th contnts or lngth of th plaintxt to b rcovrd. Ths algorithms ar typically usd to provid a digital fingrprint of a fil's contnt, oftn usd to nsur that th fil has not bn altrd by an intrudr or virus. Hash functions ar also commonly mployd by many oprating systms to ncrypt passwords to provid som masur of th intgrity of a fil. 2.1 Th RSA Algorithm for Crating RSA Public and Privat Ky Pair NO START Rad plaintxt, p, q and d. Ar p and q prim numbrs? YES n = p*q phi = (p-1)*(q-1) Th RSA algorithm can b usd for both ky xchang and digital signaturs. Although mployd with numbrs using hundrds of digits, th mathmatics bhind RSA is rlativly straight-forward. To crat an RSA public and privat ky pair, th following stps can b usd: i. Choos two prim numbrs, p and q. From ths numbrs you can calculat th modulus, n = pq ii. Slct a third numbr,, that is rlativly prim to (i.. it dos not divid vnly into) th product ( p 1)( q 1), th numbr is th public xponnt. iii. Calculat an intgr d from th quotint ( d 1). Th numbr d is th ( p 1)( q 1) privat xponnt. iv. Th public ky is th numbr pair ( ) n,. Although ths valus ar publicly known, it is computationally infasibl to dtrmin d from n and if p and q ar larg nough. v. To ncrypt a mssag, M, with th public ky, crats th ciphr-txt, C, using th quation: C = M Mod n vi. Th rcivr thn dcrypts th ciphr-txt with th privat ky using th quation: d M = C Mod n NO Ar and phi rlativly prim? Is ( d 1) an intgr? p 1 q 1 ( )( ) YES Encod plaintxt = ncoddtxt M = ncoddtxt C = M Mod n C = ciphrtxt Print ciphrtxt, n, and d. STOP Figur 1.0: A flow chart illustrating th RSA dcryption Algorithm
IJCSNS Intrnational Journal of Computr Scinc and Ntwork Scurity, VOL.13 No.7, July 2013 11 2.1 How to Us th Kys for Encryption Assuming a sndr A that wants to snd a mssag to a rcivr B, th sndr will tak th following stps:- i. Obtains th rcipint B's public ky (, n) ii. Rprsnts th plaintxt mssag as a positiv intgr M. iii. Computs th ciphr-txt C = M Mod n. iv. Snd th ciphr-txt C to B. Th flow chart of th ncryption algorithm is as givn in Figur 1.0. START Rad ciphrtxt, n and d. ciphrtxt = C M = C Mod n Dcod M = plaintxt Figur 2.0: A Flow Chart to Illustrat th Dcryption Algorithm 2.2 How to Us th Kys for Dcryption For th rcipint B to rciv th mssag snt by th sndr A, th rcipint will tak th following stps:- i. Uss th privat ky (n, d) to comput M = C Mod n. ii. Extracts th plaintxt from th intgr rprsntativ M. d Print plaintxt. STOP This is actually th smallst possibl valu for th modulus n for which th RSA algorithm works. Figur 2.0 illustrats th dcryption procdurs. 2.3 Th Dsign of th Unifid Modling Languag (UML) An objct programming paradigm (of which java is on of thm) uss a unifid form of dscribing ach programming stps calld Unifid Modling Languag (UML). It is a standard notation that originatd in th mid-1990s from th work of Jams Rumbaugh, Ivar Jacobson and Grady Boch. UML is a graphical way of rprsnting and dsigning an objct orintd languag for propr dscription of ach stp involvd and th flow layout of th program itslf. This work chooss to us UML bcaus it has th advantag of clarly showing th rlationship that xists btwn th classs that form this work. Thr ar thr packags that xist in this work, thy ar: i. Th applicationgui Packag ii. Th dbintrfac Packag iii. Th ncodinganddcoding packag. Th applicationgui packag contains four classs; MainApp.java, RcivrIntrfac.java, SndrIntrfac.java and TablDisplay.java. Th dbintrfac packag only contains th RtrivMssag.java and th SndMssag.java class. Th ncodinganddcoding packag contains th EncodingAndDcoding.java class. All ths packags ar mbddd in th projct namd DataEncryptionAndDcryption. In this papr th Top-down approach is usd for th dsign of th program thrfor all th small objcts ar put togthr to form th main objct. Th individual classs of ths smallr objcts ar spcifid with nams and ar thn linkd togthr to form th major objct. Th class nams for th individual objcts ar; i. TablDisplay.java ii. SndMssag.java iii. RtrivMssag.java iv. EncodingAndDcoding Th ncssary java packags wr importd whil th databas was cratd in mysql with thr filds namly: Ciphr ID, Ciphr Txt and n with scurity administrd on it. Frams wr cratd with mnus and call th ActionListnr, SndMssag Intrfac is cratd with labls, Buttons and TxtAras. This is followd by cration of anothr RtrivMssag intrfac with Labl, Buttons and TxtAras. And in addition, th Encoding and Dcoding class (which is a public class that ncods, dcods, ncrypt and dcrypt by making us of th BigIntgr) wr also cratd.
12 IJCSNS Intrnational Journal of Computr Scinc and Ntwork Scurity, VOL.13 No.7, July 2013 JFram - JLabl - JTxtARa - JButton + Init componnts + ActionPrformd + BigIntgr ActionListnr (-) implis privat. (+) implis public. Th Encrypt Button is clickd, a Dialog box appar asking for th valu of q, which must b a prim numbr and anothr dialog box prompting for th valu of p which must also b prim numbr (th product of q and p must not hav mor than 4 digits; which is th spcifid block-siz for this program). To snd th Ciphr txt to th databas, th Snd Button is clickd and th dialog box rturns th valu of n, and d as 9557, 17 and 7973 rspctivly. Figur 3.0: A UML to Illustrat th Program Dsign for th Privat and Public Kys 3. Rsults and Discussion Th program was run and compild on Windows XP and tstd on Univrsity of Agricultur, Makurdi local ara ntwork which is structurd on V-LAN topology. Th Graphic Usr Intrfac (GUI) is dsignd to b usr frindly and can b usd without knowldg of programming in Java. 3.1 Th Snt Mssag GUI Output. Running th program givs a fram with mnus that can snd or rtriv a mssag from th databas. Th sndr snt a tst mssag my crdit card numbr is 234M99934. Th Plaintxt ( my crdit card numbr is 234M99934 ) is ntrd in th plain txt ara bfor clicking on ncod to convrt th txt to ASCII cod and th rsult is placd in th Encodd Txt as shown in Figur 4.0. Figur 5.0: A Dialog Box Rturning th Valus of n, and d. At th rcivr nd, th rcivr uss th Rtriv Mssag GUI to rqust for th valu of ciphr ID from th databas. A corrct ntry of th Ciphr ID will rturn th Ciphr txt dialog box and rqusting for valu of d for dcryption to tak plac as shown in Figur 5.0. Th databas idntifis th mssag and th corrsponding Ciphr ID. This convrts th Ciphr txt to ASCII cods and rturns it in th Encodd Txt box. Figur 6.0: A Corrct Entry of th Ciphr ID with th Rqustd Valu of d. Figur 4.0: Th GUI of th Plain Txt, Encodd Txt and Ciphr Txt Rsult. For a corrct Ciphr ID, th dialog box will rturn th corrct Ciphr txt as shown in Figur 6.0. Corrct ntry of th valu of d at th Rcivr Intrfac will rturn th Corrct Rtrivd Plain Txt Mssag as shown in Figur 7.0.
IJCSNS Intrnational Journal of Computr Scinc and Ntwork Scurity, VOL.13 No.7, July 2013 13 Figur 7.0: Rcivr Intrfac with th Corrct Rtrivd Plain Txt Mssag. To nsur that th data is scurd, for any ntry of wrong valu of d, th Rcivr Intrfac will rturn a maninglss Plain Txt Mssag as shown in Figur 8.0. This nsurs th data is scurd against hackrs within th ntwork nvironmnt. Rfrncs [1] Afolabi, A.O and E.R. Adagunodo, 2012. Implmntation of an Improvd data ncryption algorithm in a wb basd larning systm. Intrnational Journal of rsarch and rviws in Computr Scinc. Vol. 3, No. 1. [2] Bhoopndra, S.R., Prashanna, G. and S. Yadav, 2010. An Intgratd ncryption schm usd in Blutooth communication mchanism. Intrnational Journal of Computr Tch. and Elctronics Enginring (IJCTEE), vol. 1, issu 2. [3] DI managmnt (2005) RSA algorithm, availabl at: http://www.di-mgt.com.au/rsa_alg.html. [4] Gaurav, S., 2012. Scur fil transmission schm basd On hybrid ncryption tchniqu. Intrnational Journal of managmnt, IT and Enginring. Vol. 2, issu 1. [5] Hllman, M. and J. Diffi, 1976. Nw Dirctions in Cryptography. IEEE transactions on Information thory, vol. IT-22, pp:644-654. [6] Shind, G.N. and H.S. Fad War, 2008. Fastr RSA algorithm for dcryption using Chins rmaindr thorm. ICCES, Vol. 5, No. 4, pp. 255-261. [7] Yang L. and S.H. Yang. 2007. A fram work of scurity and safty chcking for intrnt-basd control systms. Intrnational Journal of Information and Computr scurity. Vol.1, No. 2. [8] Washington, L.C. 2006. Introduction to Cryptography: with coding thory by Wad Trapp. Uppr Saddl Rivr, Nw Jrsy, Parson Prntic Hall. [9] Wuling Rn Collg of Computr and Information Enginring Zhjiang Gongshang Univrsity. 2010. A hybrid ncryption algorithm basd on DES and RSA in Blutooth communication. Scond Intrnational Confrnc on Modling, Simulation and Visualization mthods. Figur 8.0 Intrfac Shows a Maninglss Mssag with Wrong Valu of d. 4. Conclusion Nntaw Y. Goshw rcivd B. Enginring in Elctrical/ Elctronic from Univrsity of Agricultur, Makurdi and M. Enginring dgrs in Elctronics from ATBU Bauchi in 1992 and 2000, rspctivly and a PhD from Univrsity of Nigria, Nsukka. H Joind th Univrsity in 1996 and doubls as both a Lcturr in th Dpartmnt of Elctrical/Elctronic Enginring, and Dirctor of Information and Communication Tchnology, Univrsity of Agricultur, Makurdi, Nigria. Th papr has prsntd data ncryption and dcryption in a ntwork nvironmnt that was succssfully implmntd. With this softwar, data can b transfrrd from on computr trminal to anothr via an unscurd ntwork nvironmnt. An avsdroppr that braks into th mssag will rturn a maninglss mssag. Obviously ncryption and dcryption is on of th bst ways of hiding th manings of a mssag from intrudrs in a ntwork nvironmnt.