| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782 |
- // !!! DO NOT EDIT - This file is generated automatically - DO NOT EDIT !!!
- // Note: Key and IV will be different each time the file is generated
- //
- // SymmetricAlgorithmTest.cs - NUnit Test Cases for SymmetricAlgorithmTest
- //
- // Author:
- // Sebastien Pouliot ([email protected])
- //
- // (C) 2002 Motus Technologies Inc. (http://www.motus.com)
- //
- using NUnit.Framework;
- using System;
- using System.Security.Cryptography;
- using System.Text;
- namespace MonoTests.System.Security.Cryptography {
- public class SymmetricAlgorithmTest : TestCase {
- public void AssertEquals (string msg, byte[] array1, byte[] array2)
- {
- AllTests.AssertEquals (msg, array1, array2);
- }
- //--8<-- NON GENERATED CODE STARTS HERE --8<----8<----8<----8<----8<----8<--
- //-->8-- NON GENERATED CODE ENDS HERE -->8---->8---->8---->8---->8---->8--
- private void Encrypt (ICryptoTransform trans, byte[] input, byte[] output)
- {
- int bs = trans.InputBlockSize;
- int full = input.Length / bs;
- int partial = input.Length % bs;
- int pos = 0;
- for (int i=0; i < full; i++) {
- trans.TransformBlock (input, pos, bs, output, pos);
- pos += bs;
- }
- if (partial > 0) {
- byte[] final = trans.TransformFinalBlock (input, pos, partial);
- Array.Copy (final, 0, output, pos, bs);
- }
- }
- private void Decrypt (ICryptoTransform trans, byte[] input, byte[] output)
- {
- int bs = trans.InputBlockSize;
- int full = input.Length / bs;
- int partial = input.Length % bs;
- int pos = 0;
- for (int i=0; i < full; i++) {
- trans.TransformBlock (input, pos, bs, output, pos);
- pos += bs;
- }
- if (partial > 0) {
- byte[] final = trans.TransformFinalBlock (input, pos, partial);
- Array.Copy (final, 0, output, pos, partial);
- }
- }
- public void TestDES_k64b64_ECB_None ()
- {
- byte[] key = { 0x12, 0xE7, 0x7B, 0xBF, 0x11, 0x90, 0x9D, 0xB0 };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0xD2, 0x0E, 0xA7, 0xA4, 0x00, 0xF3, 0x17, 0x69 };
- byte[] expected = { 0x4B, 0x63, 0x6D, 0x2C, 0xA7, 0x0B, 0x77, 0x1C, 0x4B, 0x63, 0x6D, 0x2C, 0xA7, 0x0B, 0x77, 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = DES.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("DES_k64b64_ECB_None Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("DES_k64b64_ECB_None b1==b2", block1, block2);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("DES_k64b64_ECB_None Decrypt", input, original);
- }
- public void TestDES_k64b64_ECB_Zeros ()
- {
- byte[] key = { 0x2E, 0xCA, 0x2E, 0xC9, 0x1A, 0xB6, 0x9A, 0x5A };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0x79, 0x75, 0xD0, 0x3F, 0xFD, 0x1B, 0x12, 0x13 };
- byte[] expected = { 0x9B, 0x58, 0x07, 0x30, 0xE5, 0xDA, 0x3E, 0x7F, 0x9B, 0x58, 0x07, 0x30, 0xE5, 0xDA, 0x3E, 0x7F, 0x9B, 0x58, 0x07, 0x30, 0xE5, 0xDA, 0x3E, 0x7F };
- SymmetricAlgorithm algo = DES.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("DES_k64b64_ECB_Zeros Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("DES_k64b64_ECB_Zeros b1==b2", block1, block2);
- // also if padding is Zeros then all three blocks should be equals
- byte[] block3 = new byte[blockLength];
- Array.Copy (output, blockLength, block3, 0, blockLength);
- AssertEquals ("DES_k64b64_ECB_Zeros b1==b3", block1, block3);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("DES_k64b64_ECB_Zeros Decrypt", input, original);
- }
- public void TestDES_k64b64_ECB_PKCS7 ()
- {
- byte[] key = { 0x32, 0xE8, 0x8D, 0xF7, 0xDC, 0xFC, 0x6C, 0xCD };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0x74, 0xB2, 0x5E, 0x33, 0xBD, 0xA3, 0xC1, 0xB8 };
- byte[] expected = { 0x0E, 0xB6, 0xA5, 0x6F, 0x4A, 0xAE, 0xED, 0x95, 0x0E, 0xB6, 0xA5, 0x6F, 0x4A, 0xAE, 0xED, 0x95, 0x45, 0xEC, 0x24, 0x40, 0xF4, 0xB3, 0x97, 0xF3 };
- SymmetricAlgorithm algo = DES.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("DES_k64b64_ECB_PKCS7 Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("DES_k64b64_ECB_PKCS7 b1==b2", block1, block2);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("DES_k64b64_ECB_PKCS7 Decrypt", input, original);
- }
- public void TestDES_k64b64_CBC_None ()
- {
- byte[] key = { 0x91, 0xB4, 0x33, 0xB9, 0xA3, 0x7C, 0x47, 0x76 };
- byte[] iv = { 0x96, 0x98, 0xCC, 0x84, 0xDD, 0xC3, 0xA1, 0x14 };
- byte[] expected = { 0x71, 0x8A, 0xD7, 0xC1, 0x3F, 0xBC, 0x0C, 0xB7, 0xB7, 0x91, 0x96, 0x6A, 0xA9, 0xA6, 0xFC, 0xA1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = DES.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("DES_k64b64_CBC_None Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("DES_k64b64_CBC_None Decrypt", input, original);
- }
- public void TestDES_k64b64_CBC_Zeros ()
- {
- byte[] key = { 0x4A, 0x8B, 0xC7, 0xC5, 0x9C, 0x10, 0xB4, 0x6C };
- byte[] iv = { 0x4B, 0x53, 0x53, 0xEA, 0xAF, 0xCC, 0x5A, 0x2B };
- byte[] expected = { 0xCA, 0xBC, 0xB7, 0xB9, 0xCF, 0x72, 0x63, 0x1F, 0x83, 0x96, 0xA4, 0xB7, 0x95, 0xF7, 0xFE, 0x13, 0x90, 0x6A, 0x4B, 0x74, 0x9E, 0xE0, 0xF9, 0x30 };
- SymmetricAlgorithm algo = DES.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("DES_k64b64_CBC_Zeros Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("DES_k64b64_CBC_Zeros Decrypt", input, original);
- }
- public void TestDES_k64b64_CBC_PKCS7 ()
- {
- byte[] key = { 0xEA, 0x7D, 0x6D, 0x2C, 0xB8, 0x93, 0x33, 0xF4 };
- byte[] iv = { 0x77, 0xE4, 0xAA, 0x7C, 0xFE, 0xA9, 0x0F, 0x94 };
- byte[] expected = { 0x83, 0xB0, 0x83, 0xCA, 0xAC, 0x64, 0xE3, 0xDF, 0x1F, 0x5B, 0xE2, 0x9C, 0x16, 0x3E, 0x68, 0x91, 0x9E, 0xE5, 0xB5, 0x67, 0x80, 0xD2, 0x52, 0xC6 };
- SymmetricAlgorithm algo = DES.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("DES_k64b64_CBC_PKCS7 Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("DES_k64b64_CBC_PKCS7 Decrypt", input, original);
- }
- /* Invalid parameters DES_k64b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters DES_k64b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters DES_k64b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
- public void TestDES_k64b64_CFB8_None ()
- {
- byte[] key = { 0x52, 0x5E, 0x49, 0x90, 0x10, 0x20, 0x6D, 0x5C };
- byte[] iv = { 0x00, 0x45, 0x9B, 0x7F, 0xC2, 0x9D, 0x90, 0x37 };
- byte[] expected = { 0x9C, 0x9F, 0xE0, 0x9F, 0x2E, 0x0C, 0xE0, 0xBA, 0xD3, 0x2F, 0xF4, 0x54, 0x89, 0x83, 0x82, 0xF0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = DES.Create ();
- algo.Mode = CipherMode.CFB;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 64;
- algo.FeedbackSize = 8;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("DES_k64b64_CFB8_None Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("DES_k64b64_CFB8_None Decrypt", input, original);
- }
- public void TestDES_k64b64_CFB8_Zeros ()
- {
- byte[] key = { 0xAF, 0x35, 0x0A, 0x91, 0x8F, 0x45, 0x46, 0xAF };
- byte[] iv = { 0x3A, 0xF5, 0xCD, 0x22, 0xDC, 0xEF, 0xF4, 0x61 };
- byte[] expected = { 0xFB, 0x7E, 0xA8, 0xEC, 0xC0, 0x65, 0x30, 0xE3, 0x84, 0xBC, 0x49, 0xB9, 0x1C, 0xFD, 0xF6, 0x81, 0xCE, 0x2A, 0x69, 0x70, 0x73, 0xF0, 0x9A, 0xA8 };
- SymmetricAlgorithm algo = DES.Create ();
- algo.Mode = CipherMode.CFB;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 64;
- algo.FeedbackSize = 8;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("DES_k64b64_CFB8_Zeros Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("DES_k64b64_CFB8_Zeros Decrypt", input, original);
- }
- public void TestDES_k64b64_CFB8_PKCS7 ()
- {
- byte[] key = { 0x5D, 0xAD, 0x6F, 0xFF, 0x48, 0x89, 0x18, 0xE6 };
- byte[] iv = { 0x98, 0x46, 0xD3, 0xFC, 0x1A, 0x59, 0xF6, 0x20 };
- byte[] expected = { 0xC3, 0xAC, 0xCF, 0x49, 0xFF, 0x46, 0x82, 0x21, 0xE8, 0x1F, 0x31, 0x4E, 0x1C, 0x33, 0xEA, 0x49, 0x54, 0x67, 0x3E, 0x9C, 0xFD, 0x77, 0x39, 0x69 };
- SymmetricAlgorithm algo = DES.Create ();
- algo.Mode = CipherMode.CFB;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 64;
- algo.FeedbackSize = 8;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("DES_k64b64_CFB8_PKCS7 Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("DES_k64b64_CFB8_PKCS7 Decrypt", input, original);
- }
- /* Invalid parameters DES_k64b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters DES_k64b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters DES_k64b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
- public void TestRC2_k40b64_ECB_None ()
- {
- byte[] key = { 0xC3, 0x69, 0xCB, 0x65, 0x22 };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0x5E, 0x8E, 0xDB, 0xFD, 0x10, 0x1F, 0x14, 0x90 };
- byte[] expected = { 0xCC, 0x71, 0xF5, 0xC1, 0x2F, 0xAF, 0xB8, 0xF4, 0xCC, 0x71, 0xF5, 0xC1, 0x2F, 0xAF, 0xB8, 0xF4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k40b64_ECB_None Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("RC2_k40b64_ECB_None b1==b2", block1, block2);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k40b64_ECB_None Decrypt", input, original);
- }
- public void TestRC2_k40b64_ECB_Zeros ()
- {
- byte[] key = { 0x12, 0x66, 0x49, 0x15, 0xBC };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0x3C, 0x1C, 0x38, 0x12, 0x1C, 0x78, 0x0C, 0x19 };
- byte[] expected = { 0xDF, 0xD0, 0xD8, 0x24, 0xD8, 0x22, 0x51, 0x7C, 0xDF, 0xD0, 0xD8, 0x24, 0xD8, 0x22, 0x51, 0x7C, 0xDF, 0xD0, 0xD8, 0x24, 0xD8, 0x22, 0x51, 0x7C };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k40b64_ECB_Zeros Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("RC2_k40b64_ECB_Zeros b1==b2", block1, block2);
- // also if padding is Zeros then all three blocks should be equals
- byte[] block3 = new byte[blockLength];
- Array.Copy (output, blockLength, block3, 0, blockLength);
- AssertEquals ("RC2_k40b64_ECB_Zeros b1==b3", block1, block3);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k40b64_ECB_Zeros Decrypt", input, original);
- }
- public void TestRC2_k40b64_ECB_PKCS7 ()
- {
- byte[] key = { 0xC2, 0x76, 0x2F, 0xCE, 0xED };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0xB1, 0x88, 0x93, 0x03, 0xDA, 0x23, 0xE6, 0x87 };
- byte[] expected = { 0xE2, 0x9B, 0x89, 0x15, 0xEC, 0x57, 0x0B, 0x05, 0xE2, 0x9B, 0x89, 0x15, 0xEC, 0x57, 0x0B, 0x05, 0x44, 0x77, 0xF0, 0x47, 0x2A, 0x12, 0xEA, 0xA1 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k40b64_ECB_PKCS7 Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("RC2_k40b64_ECB_PKCS7 b1==b2", block1, block2);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k40b64_ECB_PKCS7 Decrypt", input, original);
- }
- public void TestRC2_k40b64_CBC_None ()
- {
- byte[] key = { 0xD0, 0xE1, 0x4E, 0x9C, 0x58 };
- byte[] iv = { 0x8E, 0x5E, 0x76, 0x18, 0xB8, 0x76, 0xCF, 0x77 };
- byte[] expected = { 0x36, 0x1B, 0x18, 0x98, 0xEE, 0xC6, 0x18, 0xB8, 0x67, 0xC0, 0x92, 0x09, 0x22, 0xDC, 0x65, 0xC5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k40b64_CBC_None Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k40b64_CBC_None Decrypt", input, original);
- }
- public void TestRC2_k40b64_CBC_Zeros ()
- {
- byte[] key = { 0xB5, 0x6F, 0xC7, 0x4F, 0xF8 };
- byte[] iv = { 0xB6, 0x95, 0xE9, 0x3E, 0x04, 0x98, 0x39, 0x3D };
- byte[] expected = { 0x32, 0x10, 0x36, 0x24, 0x9F, 0xB6, 0x87, 0x4E, 0x00, 0xB6, 0xEF, 0x33, 0x52, 0x8B, 0xDE, 0x8A, 0x90, 0xE2, 0x0C, 0x60, 0xD3, 0x1A, 0x72, 0xCC };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k40b64_CBC_Zeros Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k40b64_CBC_Zeros Decrypt", input, original);
- }
- public void TestRC2_k40b64_CBC_PKCS7 ()
- {
- byte[] key = { 0x67, 0xB6, 0xEE, 0xF5, 0x21 };
- byte[] iv = { 0xD3, 0xF1, 0xE7, 0xFF, 0x23, 0x92, 0xDC, 0xD9 };
- byte[] expected = { 0x24, 0x2F, 0x90, 0xAE, 0x75, 0x8E, 0x0C, 0x7F, 0xCA, 0xE4, 0xE7, 0x87, 0x2D, 0xEE, 0x9E, 0x30, 0x49, 0xF0, 0xBB, 0xC4, 0x4C, 0x8D, 0x44, 0x5C };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k40b64_CBC_PKCS7 Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k40b64_CBC_PKCS7 Decrypt", input, original);
- }
- /* Invalid parameters RC2_k40b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters RC2_k40b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters RC2_k40b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
- public void TestRC2_k40b64_CFB8_None ()
- {
- byte[] key = { 0x35, 0xCF, 0xA0, 0x20, 0x56 };
- byte[] iv = { 0xC5, 0x47, 0xFA, 0x9D, 0x19, 0x4F, 0xA9, 0x06 };
- byte[] expected = { 0xEF, 0xF9, 0xE1, 0xEE, 0x23, 0x89, 0xF6, 0x6B, 0x1F, 0xA6, 0x07, 0xAC, 0x73, 0x4A, 0xC1, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CFB;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 64;
- algo.FeedbackSize = 8;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k40b64_CFB8_None Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k40b64_CFB8_None Decrypt", input, original);
- }
- public void TestRC2_k40b64_CFB8_Zeros ()
- {
- byte[] key = { 0xDA, 0xD8, 0xF9, 0x76, 0xE4 };
- byte[] iv = { 0xAA, 0xC5, 0x42, 0xF9, 0x88, 0x42, 0x09, 0xB4 };
- byte[] expected = { 0x49, 0x08, 0xFD, 0x7B, 0x1A, 0xA2, 0xDB, 0xF3, 0xB7, 0x13, 0x01, 0x4F, 0xB8, 0x79, 0x3A, 0x0E, 0xA0, 0x11, 0x1E, 0x27, 0xA7, 0xFE, 0xFA, 0x48 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CFB;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 64;
- algo.FeedbackSize = 8;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k40b64_CFB8_Zeros Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k40b64_CFB8_Zeros Decrypt", input, original);
- }
- public void TestRC2_k40b64_CFB8_PKCS7 ()
- {
- byte[] key = { 0xDF, 0x8C, 0xC7, 0x3C, 0xDE };
- byte[] iv = { 0x1D, 0x0A, 0x92, 0x74, 0xD6, 0xEB, 0x99, 0x0F };
- byte[] expected = { 0xF9, 0x7A, 0x8E, 0xE1, 0xF2, 0x93, 0xB8, 0xCF, 0xD4, 0x7C, 0xF8, 0x81, 0x7F, 0x53, 0x7C, 0x8F, 0x42, 0x8C, 0xC4, 0xFB, 0x9E, 0x0C, 0x65, 0x53 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CFB;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 64;
- algo.FeedbackSize = 8;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k40b64_CFB8_PKCS7 Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k40b64_CFB8_PKCS7 Decrypt", input, original);
- }
- /* Invalid parameters RC2_k40b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters RC2_k40b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters RC2_k40b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
- public void TestRC2_k48b64_ECB_None ()
- {
- byte[] key = { 0xAA, 0x37, 0x60, 0x52, 0x8A, 0xBE };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0x0D, 0x5B, 0x94, 0x0F, 0x9A, 0x87, 0x08, 0x56 };
- byte[] expected = { 0xB4, 0xB4, 0x2B, 0x12, 0x9C, 0x07, 0xD4, 0xC9, 0xB4, 0xB4, 0x2B, 0x12, 0x9C, 0x07, 0xD4, 0xC9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k48b64_ECB_None Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("RC2_k48b64_ECB_None b1==b2", block1, block2);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k48b64_ECB_None Decrypt", input, original);
- }
- public void TestRC2_k48b64_ECB_Zeros ()
- {
- byte[] key = { 0x9B, 0x92, 0x8C, 0xC2, 0x18, 0xA3 };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0xB7, 0xC2, 0xAD, 0x13, 0x0A, 0x62, 0x0A, 0x50 };
- byte[] expected = { 0x24, 0x74, 0x0F, 0x4B, 0xAA, 0xB1, 0xB8, 0xF5, 0x24, 0x74, 0x0F, 0x4B, 0xAA, 0xB1, 0xB8, 0xF5, 0x24, 0x74, 0x0F, 0x4B, 0xAA, 0xB1, 0xB8, 0xF5 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k48b64_ECB_Zeros Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("RC2_k48b64_ECB_Zeros b1==b2", block1, block2);
- // also if padding is Zeros then all three blocks should be equals
- byte[] block3 = new byte[blockLength];
- Array.Copy (output, blockLength, block3, 0, blockLength);
- AssertEquals ("RC2_k48b64_ECB_Zeros b1==b3", block1, block3);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k48b64_ECB_Zeros Decrypt", input, original);
- }
- public void TestRC2_k48b64_ECB_PKCS7 ()
- {
- byte[] key = { 0x58, 0x1A, 0xD6, 0x96, 0x02, 0x75 };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0x56, 0x83, 0x39, 0x7F, 0x3B, 0xD9, 0xB0, 0x33 };
- byte[] expected = { 0x87, 0x46, 0x9E, 0xFF, 0x4B, 0xE8, 0xDA, 0xF2, 0x87, 0x46, 0x9E, 0xFF, 0x4B, 0xE8, 0xDA, 0xF2, 0x31, 0x54, 0x04, 0x63, 0xE0, 0x76, 0x74, 0x39 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k48b64_ECB_PKCS7 Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("RC2_k48b64_ECB_PKCS7 b1==b2", block1, block2);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k48b64_ECB_PKCS7 Decrypt", input, original);
- }
- public void TestRC2_k48b64_CBC_None ()
- {
- byte[] key = { 0x21, 0x9A, 0xD6, 0x31, 0x99, 0x81 };
- byte[] iv = { 0x5E, 0x6E, 0xB6, 0x33, 0xC0, 0x25, 0xAE, 0x5C };
- byte[] expected = { 0x35, 0xFA, 0x8F, 0x4F, 0x75, 0xD1, 0x10, 0x11, 0xC0, 0xA4, 0x73, 0x69, 0xBD, 0xD2, 0xE3, 0x9D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k48b64_CBC_None Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k48b64_CBC_None Decrypt", input, original);
- }
- public void TestRC2_k48b64_CBC_Zeros ()
- {
- byte[] key = { 0x59, 0x0A, 0xD4, 0x25, 0xA5, 0xB9 };
- byte[] iv = { 0x10, 0x2D, 0x42, 0x54, 0xC8, 0x97, 0xD0, 0xA7 };
- byte[] expected = { 0x4F, 0x1A, 0x5F, 0xD0, 0xA2, 0x54, 0x57, 0x60, 0x55, 0x9B, 0x4D, 0x1B, 0x55, 0xC9, 0x30, 0xA9, 0x7E, 0xF6, 0xAF, 0xFB, 0x50, 0x8B, 0xC0, 0xB6 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k48b64_CBC_Zeros Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k48b64_CBC_Zeros Decrypt", input, original);
- }
- public void TestRC2_k48b64_CBC_PKCS7 ()
- {
- byte[] key = { 0x39, 0x6C, 0xB3, 0x7B, 0xB5, 0xA9 };
- byte[] iv = { 0x42, 0x56, 0x99, 0x18, 0xA8, 0x96, 0x93, 0x5D };
- byte[] expected = { 0x92, 0x8B, 0x67, 0xC7, 0xAE, 0xF3, 0xF7, 0x03, 0x24, 0x67, 0xAC, 0xEA, 0xFE, 0xB7, 0x6B, 0x1E, 0x53, 0xB3, 0xF5, 0xDB, 0x64, 0x63, 0xB3, 0xE5 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k48b64_CBC_PKCS7 Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k48b64_CBC_PKCS7 Decrypt", input, original);
- }
- /* Invalid parameters RC2_k48b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters RC2_k48b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters RC2_k48b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
- public void TestRC2_k48b64_CFB8_None ()
- {
- byte[] key = { 0x06, 0xCE, 0x23, 0x86, 0xEC, 0xB3 };
- byte[] iv = { 0x14, 0xF7, 0xBA, 0xEC, 0xC2, 0x4A, 0x26, 0x6D };
- byte[] expected = { 0x69, 0x7A, 0x1A, 0xCC, 0x40, 0x41, 0x78, 0xC1, 0xFA, 0x89, 0x90, 0x7F, 0xC1, 0x1C, 0x27, 0x4D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CFB;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 64;
- algo.FeedbackSize = 8;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k48b64_CFB8_None Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k48b64_CFB8_None Decrypt", input, original);
- }
- public void TestRC2_k48b64_CFB8_Zeros ()
- {
- byte[] key = { 0x4B, 0xC8, 0x03, 0x4F, 0x43, 0x27 };
- byte[] iv = { 0x02, 0x24, 0xB8, 0xE9, 0xF6, 0x19, 0xA1, 0x81 };
- byte[] expected = { 0xE2, 0xD2, 0x50, 0x68, 0x56, 0x61, 0x30, 0x72, 0xA2, 0xDE, 0x97, 0xF5, 0x5C, 0xE9, 0xD5, 0xA0, 0x35, 0xD2, 0xC3, 0xEB, 0xC9, 0x2A, 0x64, 0x4D };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CFB;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 64;
- algo.FeedbackSize = 8;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k48b64_CFB8_Zeros Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k48b64_CFB8_Zeros Decrypt", input, original);
- }
- public void TestRC2_k48b64_CFB8_PKCS7 ()
- {
- byte[] key = { 0x22, 0x94, 0x8C, 0x13, 0x7F, 0x7A };
- byte[] iv = { 0x4B, 0xDF, 0xB8, 0xBF, 0x0D, 0xBE, 0x1E, 0x3D };
- byte[] expected = { 0x24, 0xE9, 0x2B, 0xBF, 0x84, 0x49, 0x4D, 0x2B, 0xC4, 0xD8, 0xEE, 0xAB, 0x52, 0x03, 0xC6, 0xAF, 0x19, 0x0A, 0x5B, 0x38, 0xB6, 0xF1, 0x98, 0x6F };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CFB;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 64;
- algo.FeedbackSize = 8;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k48b64_CFB8_PKCS7 Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k48b64_CFB8_PKCS7 Decrypt", input, original);
- }
- /* Invalid parameters RC2_k48b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters RC2_k48b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters RC2_k48b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
- public void TestRC2_k56b64_ECB_None ()
- {
- byte[] key = { 0xCA, 0x6B, 0x7A, 0xA1, 0xB1, 0x6E, 0x4A };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0xF0, 0xA9, 0x35, 0xDB, 0x4F, 0xB5, 0x3D, 0xE4 };
- byte[] expected = { 0x23, 0x39, 0x2D, 0xD9, 0x7C, 0xC0, 0xFF, 0x64, 0x23, 0x39, 0x2D, 0xD9, 0x7C, 0xC0, 0xFF, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k56b64_ECB_None Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("RC2_k56b64_ECB_None b1==b2", block1, block2);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k56b64_ECB_None Decrypt", input, original);
- }
- public void TestRC2_k56b64_ECB_Zeros ()
- {
- byte[] key = { 0x96, 0x43, 0x86, 0xAA, 0x0E, 0x66, 0x95 };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0xD3, 0xD7, 0x93, 0xED, 0xAF, 0xD6, 0x83, 0x3F };
- byte[] expected = { 0x1C, 0x72, 0x96, 0xCF, 0x7D, 0x18, 0xDB, 0x4B, 0x1C, 0x72, 0x96, 0xCF, 0x7D, 0x18, 0xDB, 0x4B, 0x1C, 0x72, 0x96, 0xCF, 0x7D, 0x18, 0xDB, 0x4B };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k56b64_ECB_Zeros Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("RC2_k56b64_ECB_Zeros b1==b2", block1, block2);
- // also if padding is Zeros then all three blocks should be equals
- byte[] block3 = new byte[blockLength];
- Array.Copy (output, blockLength, block3, 0, blockLength);
- AssertEquals ("RC2_k56b64_ECB_Zeros b1==b3", block1, block3);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k56b64_ECB_Zeros Decrypt", input, original);
- }
- public void TestRC2_k56b64_ECB_PKCS7 ()
- {
- byte[] key = { 0x5A, 0x29, 0xE4, 0x77, 0x99, 0x9D, 0x5B };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0xA6, 0x7B, 0x92, 0x40, 0x74, 0x9E, 0x0D, 0xAD };
- byte[] expected = { 0xE1, 0xBB, 0xAA, 0x43, 0x54, 0x2E, 0xFF, 0x3A, 0xE1, 0xBB, 0xAA, 0x43, 0x54, 0x2E, 0xFF, 0x3A, 0x2E, 0xA1, 0x81, 0xF1, 0x85, 0x86, 0x35, 0x97 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k56b64_ECB_PKCS7 Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("RC2_k56b64_ECB_PKCS7 b1==b2", block1, block2);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k56b64_ECB_PKCS7 Decrypt", input, original);
- }
- public void TestRC2_k56b64_CBC_None ()
- {
- byte[] key = { 0xDD, 0x2F, 0x84, 0x9F, 0xBA, 0xB1, 0xF3 };
- byte[] iv = { 0x97, 0xB2, 0xCD, 0x3F, 0x1E, 0x53, 0xE8, 0xA9 };
- byte[] expected = { 0x63, 0x6E, 0x62, 0xE5, 0x0F, 0x58, 0x86, 0x4A, 0xEF, 0x64, 0x4C, 0xDC, 0x36, 0x5D, 0x29, 0xC6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k56b64_CBC_None Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k56b64_CBC_None Decrypt", input, original);
- }
- public void TestRC2_k56b64_CBC_Zeros ()
- {
- byte[] key = { 0xED, 0xEE, 0x33, 0x8E, 0x97, 0x20, 0x58 };
- byte[] iv = { 0x0B, 0xAB, 0xAB, 0xED, 0xCC, 0x1C, 0x77, 0xA4 };
- byte[] expected = { 0x8B, 0x2F, 0x52, 0x93, 0x48, 0x7A, 0x54, 0x03, 0x58, 0x6A, 0x9B, 0xC4, 0x13, 0x99, 0xCD, 0xE2, 0x18, 0x31, 0x67, 0x05, 0x27, 0x90, 0x1D, 0xFE };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k56b64_CBC_Zeros Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k56b64_CBC_Zeros Decrypt", input, original);
- }
- public void TestRC2_k56b64_CBC_PKCS7 ()
- {
- byte[] key = { 0x52, 0xF6, 0xC3, 0xC3, 0x13, 0x9E, 0xF7 };
- byte[] iv = { 0x8E, 0xF8, 0xE5, 0x66, 0x64, 0x1C, 0xE6, 0xE3 };
- byte[] expected = { 0x7B, 0xD1, 0x1A, 0xD0, 0x62, 0x1B, 0x66, 0x5B, 0x92, 0xB0, 0x42, 0xC7, 0x63, 0x3A, 0x95, 0xED, 0x87, 0x6B, 0xA0, 0x88, 0x18, 0xC2, 0x92, 0xB4 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k56b64_CBC_PKCS7 Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k56b64_CBC_PKCS7 Decrypt", input, original);
- }
- /* Invalid parameters RC2_k56b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters RC2_k56b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters RC2_k56b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
- public void TestRC2_k56b64_CFB8_None ()
- {
- byte[] key = { 0xEA, 0x1D, 0xB2, 0x0E, 0x17, 0xF0, 0x4A };
- byte[] iv = { 0xB7, 0xEE, 0xEE, 0xFF, 0x36, 0x8C, 0x9B, 0xBB };
- byte[] expected = { 0x49, 0x1D, 0x32, 0xB4, 0x93, 0xEC, 0x96, 0xC9, 0xDC, 0x3B, 0x26, 0x4B, 0x3C, 0xA2, 0xE8, 0x72, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CFB;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 64;
- algo.FeedbackSize = 8;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k56b64_CFB8_None Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k56b64_CFB8_None Decrypt", input, original);
- }
- public void TestRC2_k56b64_CFB8_Zeros ()
- {
- byte[] key = { 0x24, 0x6F, 0xE0, 0xC7, 0x3C, 0xC0, 0x4B };
- byte[] iv = { 0xD7, 0x83, 0xCA, 0xB7, 0x9C, 0x6D, 0xC3, 0x25 };
- byte[] expected = { 0x37, 0xF7, 0x35, 0xF4, 0xB2, 0x0C, 0xCB, 0xC4, 0xAE, 0x42, 0x83, 0x99, 0x55, 0xF6, 0x51, 0x5A, 0x1A, 0xE7, 0x7B, 0xFD, 0x4E, 0x78, 0xD7, 0x80 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CFB;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 64;
- algo.FeedbackSize = 8;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k56b64_CFB8_Zeros Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k56b64_CFB8_Zeros Decrypt", input, original);
- }
- public void TestRC2_k56b64_CFB8_PKCS7 ()
- {
- byte[] key = { 0x58, 0xE4, 0xC8, 0x6F, 0xB4, 0x14, 0xAC };
- byte[] iv = { 0xA1, 0xBC, 0x94, 0xB5, 0xF5, 0x4F, 0x78, 0x19 };
- byte[] expected = { 0xBA, 0x15, 0xE2, 0x73, 0x56, 0x5E, 0xB6, 0x30, 0xA8, 0x50, 0xA2, 0x61, 0x52, 0x2F, 0x61, 0xCC, 0x97, 0x9A, 0x91, 0xB1, 0xF0, 0x87, 0x3F, 0xA7 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CFB;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 64;
- algo.FeedbackSize = 8;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k56b64_CFB8_PKCS7 Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k56b64_CFB8_PKCS7 Decrypt", input, original);
- }
- /* Invalid parameters RC2_k56b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters RC2_k56b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters RC2_k56b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
- public void TestRC2_k64b64_ECB_None ()
- {
- byte[] key = { 0x2C, 0x52, 0xB4, 0x93, 0xF1, 0xEA, 0xC8, 0x8F };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0xDE, 0x10, 0xA1, 0x1C, 0x5E, 0x43, 0x5F, 0x97 };
- byte[] expected = { 0xDB, 0x1D, 0x72, 0x2C, 0x7C, 0x4A, 0x31, 0xDB, 0xDB, 0x1D, 0x72, 0x2C, 0x7C, 0x4A, 0x31, 0xDB, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k64b64_ECB_None Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("RC2_k64b64_ECB_None b1==b2", block1, block2);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k64b64_ECB_None Decrypt", input, original);
- }
- public void TestRC2_k64b64_ECB_Zeros ()
- {
- byte[] key = { 0x05, 0x0C, 0x49, 0xE3, 0x25, 0x49, 0xFA, 0x35 };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0x4D, 0x94, 0x32, 0xD2, 0x8B, 0xB6, 0x52, 0x9C };
- byte[] expected = { 0x39, 0x35, 0xCE, 0x5C, 0x75, 0xF5, 0xB7, 0xA1, 0x39, 0x35, 0xCE, 0x5C, 0x75, 0xF5, 0xB7, 0xA1, 0x39, 0x35, 0xCE, 0x5C, 0x75, 0xF5, 0xB7, 0xA1 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k64b64_ECB_Zeros Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("RC2_k64b64_ECB_Zeros b1==b2", block1, block2);
- // also if padding is Zeros then all three blocks should be equals
- byte[] block3 = new byte[blockLength];
- Array.Copy (output, blockLength, block3, 0, blockLength);
- AssertEquals ("RC2_k64b64_ECB_Zeros b1==b3", block1, block3);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k64b64_ECB_Zeros Decrypt", input, original);
- }
- public void TestRC2_k64b64_ECB_PKCS7 ()
- {
- byte[] key = { 0xE6, 0x57, 0xF2, 0x73, 0x3A, 0x20, 0xB0, 0x7E };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0x34, 0x25, 0xD2, 0x35, 0x1C, 0xE4, 0x9D, 0xC6 };
- byte[] expected = { 0x7A, 0x3F, 0x95, 0xA0, 0xA1, 0x70, 0xBD, 0xC3, 0x7A, 0x3F, 0x95, 0xA0, 0xA1, 0x70, 0xBD, 0xC3, 0xDA, 0xE7, 0x0C, 0xC3, 0xAD, 0xC3, 0xEA, 0xE9 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k64b64_ECB_PKCS7 Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("RC2_k64b64_ECB_PKCS7 b1==b2", block1, block2);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k64b64_ECB_PKCS7 Decrypt", input, original);
- }
- public void TestRC2_k64b64_CBC_None ()
- {
- byte[] key = { 0x91, 0x14, 0x49, 0xC4, 0x0D, 0xF9, 0x90, 0x77 };
- byte[] iv = { 0xB9, 0xBD, 0x6B, 0x9E, 0x52, 0xC9, 0x8C, 0xA5 };
- byte[] expected = { 0xF1, 0x7C, 0xDF, 0x18, 0x54, 0xC2, 0xDE, 0x3B, 0x05, 0x20, 0x99, 0x94, 0x8A, 0x5E, 0x29, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k64b64_CBC_None Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k64b64_CBC_None Decrypt", input, original);
- }
- public void TestRC2_k64b64_CBC_Zeros ()
- {
- byte[] key = { 0x0E, 0xE0, 0xAD, 0xFD, 0x86, 0x22, 0x1D, 0x05 };
- byte[] iv = { 0xDF, 0x41, 0x2B, 0x6E, 0x82, 0x00, 0xCB, 0x38 };
- byte[] expected = { 0x98, 0x43, 0x84, 0x05, 0x68, 0xAE, 0x99, 0x3B, 0xB1, 0xCD, 0x2F, 0x69, 0xD9, 0xDD, 0x54, 0x79, 0x37, 0x36, 0x96, 0xE9, 0xC3, 0x62, 0xC2, 0x35 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k64b64_CBC_Zeros Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k64b64_CBC_Zeros Decrypt", input, original);
- }
- public void TestRC2_k64b64_CBC_PKCS7 ()
- {
- byte[] key = { 0x2D, 0x70, 0x15, 0xFF, 0x15, 0xEB, 0xDC, 0x33 };
- byte[] iv = { 0x04, 0x33, 0x63, 0x52, 0x5B, 0xA1, 0xAB, 0xAC };
- byte[] expected = { 0x07, 0x9B, 0x58, 0x27, 0xB4, 0x36, 0xDD, 0x9D, 0x7C, 0xC5, 0xE0, 0x83, 0x6A, 0x76, 0x87, 0x08, 0xF1, 0xEF, 0xCB, 0xE2, 0xA1, 0xF6, 0xA9, 0xBE };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k64b64_CBC_PKCS7 Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k64b64_CBC_PKCS7 Decrypt", input, original);
- }
- /* Invalid parameters RC2_k64b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters RC2_k64b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters RC2_k64b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
- public void TestRC2_k64b64_CFB8_None ()
- {
- byte[] key = { 0x1B, 0x23, 0x16, 0xEA, 0x19, 0xF0, 0x53, 0xEE };
- byte[] iv = { 0x60, 0x8D, 0x23, 0x2B, 0x0D, 0x56, 0x6F, 0x92 };
- byte[] expected = { 0x0C, 0xE2, 0x26, 0xA8, 0x0A, 0xB8, 0xFE, 0x03, 0x71, 0x2B, 0x56, 0x59, 0xA3, 0x45, 0xC0, 0xA1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CFB;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 64;
- algo.FeedbackSize = 8;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k64b64_CFB8_None Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k64b64_CFB8_None Decrypt", input, original);
- }
- public void TestRC2_k64b64_CFB8_Zeros ()
- {
- byte[] key = { 0x49, 0xAD, 0xCD, 0xF8, 0xB6, 0x44, 0xA1, 0x86 };
- byte[] iv = { 0xCA, 0x6A, 0x96, 0xA8, 0x18, 0xA8, 0xF6, 0x77 };
- byte[] expected = { 0x12, 0x88, 0x7D, 0xC4, 0x8A, 0x04, 0x86, 0x09, 0x4A, 0x64, 0xBE, 0x31, 0xD2, 0x1F, 0xF9, 0xA1, 0x80, 0x5D, 0x0B, 0x5A, 0x01, 0x9F, 0x10, 0x6D };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CFB;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 64;
- algo.FeedbackSize = 8;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k64b64_CFB8_Zeros Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k64b64_CFB8_Zeros Decrypt", input, original);
- }
- public void TestRC2_k64b64_CFB8_PKCS7 ()
- {
- byte[] key = { 0xF6, 0xE6, 0xA0, 0x33, 0xD3, 0x77, 0x0C, 0x28 };
- byte[] iv = { 0x50, 0x31, 0x14, 0xAF, 0x27, 0x92, 0xFC, 0x57 };
- byte[] expected = { 0xFF, 0x4B, 0xA2, 0x37, 0x56, 0xFB, 0x37, 0x4A, 0xB5, 0x6A, 0xCB, 0x27, 0x06, 0xED, 0xC2, 0x38, 0x7C, 0x4B, 0xBE, 0xC0, 0xD5, 0xD7, 0x6A, 0x79 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CFB;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 64;
- algo.FeedbackSize = 8;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k64b64_CFB8_PKCS7 Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k64b64_CFB8_PKCS7 Decrypt", input, original);
- }
- /* Invalid parameters RC2_k64b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters RC2_k64b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters RC2_k64b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
- public void TestRC2_k72b64_ECB_None ()
- {
- byte[] key = { 0xEC, 0x93, 0x9A, 0xF0, 0x51, 0x69, 0x59, 0x0B, 0x15 };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0x36, 0xDB, 0xE8, 0x7F, 0xB5, 0x43, 0x4C, 0xF6 };
- byte[] expected = { 0xD6, 0x8A, 0x11, 0x59, 0x38, 0x6B, 0x93, 0x8F, 0xD6, 0x8A, 0x11, 0x59, 0x38, 0x6B, 0x93, 0x8F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k72b64_ECB_None Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("RC2_k72b64_ECB_None b1==b2", block1, block2);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k72b64_ECB_None Decrypt", input, original);
- }
- public void TestRC2_k72b64_ECB_Zeros ()
- {
- byte[] key = { 0x19, 0x14, 0x2D, 0xF6, 0x48, 0xED, 0x5A, 0xF3, 0x1F };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0x8C, 0x1D, 0x0D, 0xC7, 0xE3, 0x77, 0x68, 0x40 };
- byte[] expected = { 0x38, 0xD4, 0x18, 0x61, 0xF6, 0x8E, 0x55, 0xD7, 0x38, 0xD4, 0x18, 0x61, 0xF6, 0x8E, 0x55, 0xD7, 0x38, 0xD4, 0x18, 0x61, 0xF6, 0x8E, 0x55, 0xD7 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k72b64_ECB_Zeros Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("RC2_k72b64_ECB_Zeros b1==b2", block1, block2);
- // also if padding is Zeros then all three blocks should be equals
- byte[] block3 = new byte[blockLength];
- Array.Copy (output, blockLength, block3, 0, blockLength);
- AssertEquals ("RC2_k72b64_ECB_Zeros b1==b3", block1, block3);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k72b64_ECB_Zeros Decrypt", input, original);
- }
- public void TestRC2_k72b64_ECB_PKCS7 ()
- {
- byte[] key = { 0x1C, 0xAA, 0x46, 0xE7, 0x37, 0x23, 0x14, 0xC9, 0x31 };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0x3B, 0x0B, 0x1D, 0xE0, 0x3A, 0x6E, 0xF3, 0x1C };
- byte[] expected = { 0x71, 0x04, 0xA2, 0x66, 0xFC, 0xB9, 0x0F, 0x48, 0x71, 0x04, 0xA2, 0x66, 0xFC, 0xB9, 0x0F, 0x48, 0xFA, 0xF7, 0x6F, 0xA9, 0xA0, 0x23, 0xF8, 0x7E };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k72b64_ECB_PKCS7 Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("RC2_k72b64_ECB_PKCS7 b1==b2", block1, block2);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k72b64_ECB_PKCS7 Decrypt", input, original);
- }
- public void TestRC2_k72b64_CBC_None ()
- {
- byte[] key = { 0xF7, 0x60, 0xC5, 0x87, 0x4E, 0x36, 0xCE, 0x3C, 0xE6 };
- byte[] iv = { 0x60, 0x0E, 0xAC, 0x58, 0x1C, 0x91, 0x1D, 0xAC };
- byte[] expected = { 0xF7, 0xFE, 0xC3, 0x0E, 0x68, 0x6C, 0x15, 0x38, 0xDC, 0x06, 0xD9, 0x3A, 0x02, 0x08, 0xE2, 0xBF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k72b64_CBC_None Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k72b64_CBC_None Decrypt", input, original);
- }
- public void TestRC2_k72b64_CBC_Zeros ()
- {
- byte[] key = { 0xD2, 0x3C, 0xD2, 0x40, 0xF1, 0x1D, 0x2E, 0xF4, 0x92 };
- byte[] iv = { 0xBE, 0x7C, 0xF7, 0xBE, 0x35, 0x11, 0x94, 0x46 };
- byte[] expected = { 0x7B, 0x6C, 0x73, 0xE4, 0x19, 0x69, 0x32, 0x61, 0x48, 0xE0, 0x21, 0x03, 0xAF, 0xC4, 0x54, 0x61, 0xE7, 0xB7, 0x00, 0x55, 0xDB, 0x57, 0x3C, 0x40 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k72b64_CBC_Zeros Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k72b64_CBC_Zeros Decrypt", input, original);
- }
- public void TestRC2_k72b64_CBC_PKCS7 ()
- {
- byte[] key = { 0xE6, 0x09, 0x99, 0x96, 0x84, 0x2D, 0x9B, 0xE9, 0x34 };
- byte[] iv = { 0x00, 0xE9, 0x3B, 0x59, 0x6C, 0x5E, 0xF3, 0x8A };
- byte[] expected = { 0xA9, 0x4E, 0x30, 0x5F, 0xEF, 0xF5, 0x77, 0xC5, 0x26, 0x96, 0xDA, 0x3E, 0x53, 0xF5, 0xCB, 0xEC, 0xBC, 0xF9, 0x85, 0x00, 0xF2, 0x0D, 0x32, 0x2D };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k72b64_CBC_PKCS7 Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k72b64_CBC_PKCS7 Decrypt", input, original);
- }
- /* Invalid parameters RC2_k72b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters RC2_k72b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters RC2_k72b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
- public void TestRC2_k72b64_CFB8_None ()
- {
- byte[] key = { 0x65, 0x6B, 0x23, 0x3F, 0xB3, 0xE5, 0x6F, 0x30, 0x01 };
- byte[] iv = { 0x10, 0x16, 0x28, 0x20, 0xAB, 0x77, 0x74, 0x46 };
- byte[] expected = { 0x5A, 0x35, 0x9B, 0x9E, 0x7A, 0xD6, 0xED, 0x1D, 0x36, 0xC9, 0x95, 0x0E, 0x04, 0xE1, 0x9C, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CFB;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 64;
- algo.FeedbackSize = 8;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k72b64_CFB8_None Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k72b64_CFB8_None Decrypt", input, original);
- }
- public void TestRC2_k72b64_CFB8_Zeros ()
- {
- byte[] key = { 0x87, 0xC1, 0x80, 0x41, 0xD6, 0xF1, 0x33, 0xC7, 0x78 };
- byte[] iv = { 0x21, 0x55, 0xCF, 0x6E, 0xF5, 0x3B, 0xF0, 0x6B };
- byte[] expected = { 0x83, 0xFC, 0xD7, 0x43, 0xC0, 0x4F, 0x9F, 0xE0, 0x60, 0xAD, 0x3B, 0x0D, 0x5A, 0xF3, 0xF3, 0x0B, 0x96, 0x25, 0x97, 0x6D, 0x58, 0x8B, 0x5A, 0x26 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CFB;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 64;
- algo.FeedbackSize = 8;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k72b64_CFB8_Zeros Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k72b64_CFB8_Zeros Decrypt", input, original);
- }
- public void TestRC2_k72b64_CFB8_PKCS7 ()
- {
- byte[] key = { 0xAE, 0xE0, 0x44, 0x66, 0xDA, 0x34, 0xFD, 0xD4, 0x71 };
- byte[] iv = { 0xFA, 0x66, 0x5F, 0x55, 0xBC, 0x1B, 0xC7, 0x83 };
- byte[] expected = { 0xF3, 0xAB, 0x63, 0x11, 0xA0, 0x27, 0x05, 0x42, 0x0A, 0xCD, 0x16, 0xCA, 0x22, 0x4E, 0x0B, 0xCB, 0x96, 0xCA, 0xD9, 0x38, 0x6D, 0x5E, 0x5E, 0x55 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CFB;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 64;
- algo.FeedbackSize = 8;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k72b64_CFB8_PKCS7 Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k72b64_CFB8_PKCS7 Decrypt", input, original);
- }
- /* Invalid parameters RC2_k72b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters RC2_k72b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters RC2_k72b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
- public void TestRC2_k80b64_ECB_None ()
- {
- byte[] key = { 0xB8, 0xA4, 0x76, 0xF8, 0x59, 0x86, 0x40, 0x53, 0x33, 0x68 };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0xFF, 0x5F, 0x8B, 0x5E, 0xCF, 0xB8, 0xA5, 0xCB };
- byte[] expected = { 0x7A, 0x56, 0x73, 0x0A, 0x72, 0x69, 0x95, 0x16, 0x7A, 0x56, 0x73, 0x0A, 0x72, 0x69, 0x95, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k80b64_ECB_None Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("RC2_k80b64_ECB_None b1==b2", block1, block2);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k80b64_ECB_None Decrypt", input, original);
- }
- public void TestRC2_k80b64_ECB_Zeros ()
- {
- byte[] key = { 0x9A, 0xE1, 0xE1, 0x17, 0xCB, 0x2B, 0x9C, 0x5D, 0x5D, 0x28 };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0x71, 0x29, 0x89, 0x9C, 0x66, 0xF5, 0x90, 0x63 };
- byte[] expected = { 0x38, 0x83, 0x30, 0xE0, 0xC6, 0x8A, 0x0B, 0x11, 0x38, 0x83, 0x30, 0xE0, 0xC6, 0x8A, 0x0B, 0x11, 0x38, 0x83, 0x30, 0xE0, 0xC6, 0x8A, 0x0B, 0x11 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k80b64_ECB_Zeros Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("RC2_k80b64_ECB_Zeros b1==b2", block1, block2);
- // also if padding is Zeros then all three blocks should be equals
- byte[] block3 = new byte[blockLength];
- Array.Copy (output, blockLength, block3, 0, blockLength);
- AssertEquals ("RC2_k80b64_ECB_Zeros b1==b3", block1, block3);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k80b64_ECB_Zeros Decrypt", input, original);
- }
- public void TestRC2_k80b64_ECB_PKCS7 ()
- {
- byte[] key = { 0x8D, 0xF8, 0xDA, 0xA2, 0x31, 0xEA, 0x86, 0x92, 0x52, 0xBB };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0xD3, 0x1C, 0x57, 0x72, 0xDE, 0xFD, 0xCA, 0xC7 };
- byte[] expected = { 0x51, 0xD4, 0x00, 0x54, 0x58, 0xE5, 0xED, 0x5C, 0x51, 0xD4, 0x00, 0x54, 0x58, 0xE5, 0xED, 0x5C, 0xCE, 0xF6, 0xDB, 0x31, 0x10, 0xE9, 0x0E, 0xD8 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k80b64_ECB_PKCS7 Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("RC2_k80b64_ECB_PKCS7 b1==b2", block1, block2);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k80b64_ECB_PKCS7 Decrypt", input, original);
- }
- public void TestRC2_k80b64_CBC_None ()
- {
- byte[] key = { 0x5B, 0x45, 0x99, 0x10, 0x47, 0x42, 0x89, 0xC8, 0x2A, 0x6C };
- byte[] iv = { 0xE4, 0x8F, 0x2A, 0x4D, 0x25, 0x38, 0x01, 0x04 };
- byte[] expected = { 0xA3, 0x23, 0xE7, 0xCD, 0xC1, 0x5E, 0x4E, 0x1D, 0x2F, 0x7F, 0x8B, 0xA7, 0xD0, 0x42, 0xF2, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k80b64_CBC_None Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k80b64_CBC_None Decrypt", input, original);
- }
- public void TestRC2_k80b64_CBC_Zeros ()
- {
- byte[] key = { 0xD4, 0x47, 0xFF, 0x5A, 0x70, 0xE8, 0x48, 0x0F, 0x23, 0xD1 };
- byte[] iv = { 0x8B, 0xF8, 0x94, 0x02, 0xB3, 0xFB, 0xB0, 0x0D };
- byte[] expected = { 0x88, 0x5C, 0x72, 0x4C, 0x35, 0x7F, 0x73, 0x1C, 0x8A, 0x06, 0x6B, 0x90, 0x82, 0xC5, 0xBC, 0x46, 0x75, 0xC1, 0x87, 0xD9, 0xED, 0x29, 0x1D, 0xB8 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k80b64_CBC_Zeros Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k80b64_CBC_Zeros Decrypt", input, original);
- }
- public void TestRC2_k80b64_CBC_PKCS7 ()
- {
- byte[] key = { 0x8D, 0x77, 0xC5, 0x6E, 0xC2, 0x8F, 0x10, 0x51, 0xD2, 0x20 };
- byte[] iv = { 0x43, 0xC5, 0x4E, 0x58, 0xF0, 0xD7, 0xB3, 0x92 };
- byte[] expected = { 0xE9, 0xB0, 0x67, 0x7C, 0x6C, 0x77, 0x68, 0x4D, 0xD0, 0xA5, 0x93, 0x9F, 0x84, 0xE0, 0xA0, 0xA9, 0x36, 0x21, 0xD7, 0x07, 0x0B, 0x8D, 0xD7, 0xB9 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k80b64_CBC_PKCS7 Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k80b64_CBC_PKCS7 Decrypt", input, original);
- }
- /* Invalid parameters RC2_k80b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters RC2_k80b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters RC2_k80b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
- public void TestRC2_k80b64_CFB8_None ()
- {
- byte[] key = { 0x2A, 0x44, 0xD9, 0x1C, 0x5E, 0x7C, 0x79, 0x3D, 0x88, 0x55 };
- byte[] iv = { 0xA0, 0x48, 0x00, 0x04, 0xA8, 0xB8, 0x83, 0x9F };
- byte[] expected = { 0xEA, 0xD0, 0x3D, 0x9A, 0x62, 0xEA, 0x9C, 0x59, 0xAC, 0xD4, 0xA1, 0xDE, 0xDB, 0x3D, 0xF8, 0x4E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CFB;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 64;
- algo.FeedbackSize = 8;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k80b64_CFB8_None Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k80b64_CFB8_None Decrypt", input, original);
- }
- public void TestRC2_k80b64_CFB8_Zeros ()
- {
- byte[] key = { 0x30, 0x51, 0xCD, 0x3B, 0x8A, 0x8A, 0x8C, 0xF4, 0x76, 0x64 };
- byte[] iv = { 0xD9, 0x5F, 0xEB, 0x11, 0x8F, 0x0A, 0x7D, 0xDC };
- byte[] expected = { 0x02, 0xB4, 0x0F, 0xB5, 0x79, 0x81, 0xAC, 0xFD, 0xBA, 0x40, 0xF1, 0x61, 0x96, 0x70, 0x09, 0x5B, 0xFF, 0x0D, 0x90, 0xB4, 0x54, 0x27, 0x4A, 0x3C };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CFB;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 64;
- algo.FeedbackSize = 8;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k80b64_CFB8_Zeros Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k80b64_CFB8_Zeros Decrypt", input, original);
- }
- public void TestRC2_k80b64_CFB8_PKCS7 ()
- {
- byte[] key = { 0xA7, 0x24, 0xA0, 0x14, 0x78, 0xDC, 0x8B, 0x99, 0x77, 0xCD };
- byte[] iv = { 0xB8, 0x68, 0xD0, 0x5A, 0x13, 0x3C, 0xBA, 0x59 };
- byte[] expected = { 0x3B, 0x35, 0xF6, 0x3F, 0x36, 0x7B, 0xF1, 0x7D, 0xCE, 0xC8, 0x62, 0xF8, 0x34, 0xC6, 0x42, 0x6F, 0x77, 0xCF, 0x32, 0x41, 0xF3, 0x0B, 0x28, 0x37 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CFB;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 64;
- algo.FeedbackSize = 8;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k80b64_CFB8_PKCS7 Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k80b64_CFB8_PKCS7 Decrypt", input, original);
- }
- /* Invalid parameters RC2_k80b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters RC2_k80b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters RC2_k80b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
- public void TestRC2_k88b64_ECB_None ()
- {
- byte[] key = { 0xCE, 0x12, 0x59, 0x88, 0x7A, 0xCD, 0x57, 0x4C, 0xCD, 0xA9, 0xD2 };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0x91, 0x4C, 0x2D, 0xB4, 0x6E, 0x19, 0x3F, 0x6F };
- byte[] expected = { 0x74, 0x25, 0xAD, 0x2E, 0x88, 0xA9, 0x3E, 0x1F, 0x74, 0x25, 0xAD, 0x2E, 0x88, 0xA9, 0x3E, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k88b64_ECB_None Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("RC2_k88b64_ECB_None b1==b2", block1, block2);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k88b64_ECB_None Decrypt", input, original);
- }
- public void TestRC2_k88b64_ECB_Zeros ()
- {
- byte[] key = { 0x28, 0xDC, 0x09, 0x80, 0x85, 0x25, 0x95, 0x41, 0x7B, 0xD4, 0x06 };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0xAE, 0x0D, 0xC1, 0x42, 0x01, 0x1C, 0x6E, 0x5A };
- byte[] expected = { 0x48, 0xD6, 0x9F, 0x9A, 0x7C, 0x93, 0x89, 0x5F, 0x48, 0xD6, 0x9F, 0x9A, 0x7C, 0x93, 0x89, 0x5F, 0x48, 0xD6, 0x9F, 0x9A, 0x7C, 0x93, 0x89, 0x5F };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k88b64_ECB_Zeros Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("RC2_k88b64_ECB_Zeros b1==b2", block1, block2);
- // also if padding is Zeros then all three blocks should be equals
- byte[] block3 = new byte[blockLength];
- Array.Copy (output, blockLength, block3, 0, blockLength);
- AssertEquals ("RC2_k88b64_ECB_Zeros b1==b3", block1, block3);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k88b64_ECB_Zeros Decrypt", input, original);
- }
- public void TestRC2_k88b64_ECB_PKCS7 ()
- {
- byte[] key = { 0xAB, 0x26, 0x7E, 0xD3, 0x3A, 0x0A, 0x3F, 0x50, 0x0B, 0x84, 0x5F };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0x28, 0x3C, 0x18, 0x06, 0x3C, 0xF7, 0x83, 0x51 };
- byte[] expected = { 0xE0, 0x60, 0x29, 0xC5, 0xE5, 0xFE, 0x75, 0x95, 0xE0, 0x60, 0x29, 0xC5, 0xE5, 0xFE, 0x75, 0x95, 0xE8, 0x61, 0x0A, 0x2A, 0x79, 0x3F, 0x0A, 0xB7 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k88b64_ECB_PKCS7 Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("RC2_k88b64_ECB_PKCS7 b1==b2", block1, block2);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k88b64_ECB_PKCS7 Decrypt", input, original);
- }
- public void TestRC2_k88b64_CBC_None ()
- {
- byte[] key = { 0x01, 0x2F, 0x45, 0x5F, 0x2D, 0x9E, 0xDB, 0x29, 0x6C, 0x54, 0xF5 };
- byte[] iv = { 0x4C, 0x6A, 0x4D, 0x77, 0x7E, 0x34, 0xB4, 0x75 };
- byte[] expected = { 0x66, 0x58, 0x7F, 0xE7, 0x6D, 0x3B, 0x6A, 0x97, 0xFC, 0x65, 0x15, 0x8D, 0xAC, 0xB0, 0xB1, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k88b64_CBC_None Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k88b64_CBC_None Decrypt", input, original);
- }
- public void TestRC2_k88b64_CBC_Zeros ()
- {
- byte[] key = { 0xA9, 0xD1, 0xDA, 0xCB, 0x4C, 0xA7, 0xD3, 0x35, 0x70, 0x1E, 0x15 };
- byte[] iv = { 0xF2, 0x17, 0x14, 0x41, 0x36, 0x58, 0x27, 0x48 };
- byte[] expected = { 0x41, 0xDD, 0xFE, 0x10, 0x56, 0xE2, 0x86, 0xDC, 0xC6, 0x53, 0x69, 0x1A, 0x2D, 0x66, 0x1D, 0x1C, 0xAD, 0x3C, 0x1F, 0xCE, 0xE3, 0xE2, 0x52, 0x13 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k88b64_CBC_Zeros Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k88b64_CBC_Zeros Decrypt", input, original);
- }
- public void TestRC2_k88b64_CBC_PKCS7 ()
- {
- byte[] key = { 0x07, 0x97, 0xCB, 0xA3, 0xB6, 0xFF, 0x57, 0x30, 0x5A, 0x2E, 0x3E };
- byte[] iv = { 0x78, 0x44, 0xCE, 0xBA, 0xC6, 0xCD, 0x0C, 0xB7 };
- byte[] expected = { 0x07, 0xCC, 0xFD, 0x12, 0x0D, 0x07, 0xED, 0xB2, 0x8C, 0xDA, 0xB9, 0xC3, 0xE7, 0x04, 0x41, 0x5A, 0xA3, 0x9C, 0x50, 0x8B, 0x8F, 0x9D, 0x2E, 0x65 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k88b64_CBC_PKCS7 Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k88b64_CBC_PKCS7 Decrypt", input, original);
- }
- /* Invalid parameters RC2_k88b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters RC2_k88b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters RC2_k88b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
- public void TestRC2_k88b64_CFB8_None ()
- {
- byte[] key = { 0x6E, 0x73, 0x03, 0xFD, 0x20, 0xAB, 0x21, 0x9D, 0x54, 0x0C, 0xB9 };
- byte[] iv = { 0x69, 0x6B, 0xF5, 0xD0, 0x10, 0xB5, 0xFE, 0xEF };
- byte[] expected = { 0x12, 0x2B, 0xF0, 0x54, 0xFF, 0x2F, 0xE2, 0xF0, 0x36, 0x9A, 0x3E, 0xFE, 0x57, 0x56, 0x0E, 0x1D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CFB;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 64;
- algo.FeedbackSize = 8;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k88b64_CFB8_None Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k88b64_CFB8_None Decrypt", input, original);
- }
- public void TestRC2_k88b64_CFB8_Zeros ()
- {
- byte[] key = { 0x8B, 0x1D, 0xD0, 0x5C, 0x3E, 0xF4, 0x5B, 0xA5, 0x56, 0x87, 0xE8 };
- byte[] iv = { 0x14, 0x01, 0x4B, 0x90, 0x67, 0x02, 0x79, 0x3F };
- byte[] expected = { 0xA1, 0x7D, 0x02, 0x58, 0xBC, 0x3E, 0x56, 0x3E, 0xF6, 0x08, 0x08, 0xB0, 0xD0, 0xD1, 0xAC, 0x9F, 0x29, 0x65, 0x18, 0x76, 0x2C, 0x96, 0xCC, 0x8C };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CFB;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 64;
- algo.FeedbackSize = 8;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k88b64_CFB8_Zeros Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k88b64_CFB8_Zeros Decrypt", input, original);
- }
- public void TestRC2_k88b64_CFB8_PKCS7 ()
- {
- byte[] key = { 0xCB, 0xD9, 0xE0, 0xD8, 0x82, 0xA0, 0x06, 0xD1, 0x6C, 0x5F, 0x8F };
- byte[] iv = { 0x73, 0x14, 0x81, 0x8C, 0x59, 0xE4, 0x33, 0xDF };
- byte[] expected = { 0x31, 0xA2, 0xA9, 0xCE, 0xAF, 0xF1, 0x8F, 0xA5, 0x02, 0xD8, 0xF5, 0xDC, 0x2C, 0x41, 0x8E, 0x64, 0x81, 0xCA, 0xBE, 0x89, 0xC3, 0x19, 0x24, 0x78 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CFB;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 64;
- algo.FeedbackSize = 8;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k88b64_CFB8_PKCS7 Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k88b64_CFB8_PKCS7 Decrypt", input, original);
- }
- /* Invalid parameters RC2_k88b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters RC2_k88b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters RC2_k88b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
- public void TestRC2_k96b64_ECB_None ()
- {
- byte[] key = { 0x72, 0xD8, 0x0A, 0x9D, 0xDA, 0x9D, 0xB1, 0x78, 0x61, 0x9C, 0xD8, 0x57 };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0x31, 0x21, 0x9D, 0xD9, 0x12, 0x95, 0x79, 0x30 };
- byte[] expected = { 0x41, 0xA6, 0x5B, 0x2D, 0x51, 0x55, 0x1B, 0xE2, 0x41, 0xA6, 0x5B, 0x2D, 0x51, 0x55, 0x1B, 0xE2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k96b64_ECB_None Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("RC2_k96b64_ECB_None b1==b2", block1, block2);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k96b64_ECB_None Decrypt", input, original);
- }
- public void TestRC2_k96b64_ECB_Zeros ()
- {
- byte[] key = { 0x5D, 0x07, 0x3C, 0x15, 0x3F, 0xE1, 0xB2, 0x72, 0x9F, 0x1A, 0xBE, 0x21 };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0x76, 0xE9, 0x93, 0x9F, 0xD1, 0x6A, 0xCE, 0x79 };
- byte[] expected = { 0x56, 0xF6, 0xF3, 0xAE, 0xCD, 0x73, 0x4F, 0x12, 0x56, 0xF6, 0xF3, 0xAE, 0xCD, 0x73, 0x4F, 0x12, 0x56, 0xF6, 0xF3, 0xAE, 0xCD, 0x73, 0x4F, 0x12 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k96b64_ECB_Zeros Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("RC2_k96b64_ECB_Zeros b1==b2", block1, block2);
- // also if padding is Zeros then all three blocks should be equals
- byte[] block3 = new byte[blockLength];
- Array.Copy (output, blockLength, block3, 0, blockLength);
- AssertEquals ("RC2_k96b64_ECB_Zeros b1==b3", block1, block3);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k96b64_ECB_Zeros Decrypt", input, original);
- }
- public void TestRC2_k96b64_ECB_PKCS7 ()
- {
- byte[] key = { 0x79, 0xCA, 0xDB, 0xBE, 0x8C, 0x10, 0x1E, 0xEB, 0x8B, 0x16, 0x00, 0x1B };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0x17, 0x42, 0x68, 0x21, 0xBC, 0x52, 0x6A, 0xF6 };
- byte[] expected = { 0x86, 0xB2, 0x84, 0xAA, 0x58, 0xCB, 0x3F, 0x19, 0x86, 0xB2, 0x84, 0xAA, 0x58, 0xCB, 0x3F, 0x19, 0x75, 0xB8, 0x91, 0xC8, 0x17, 0xE2, 0x1C, 0x4A };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k96b64_ECB_PKCS7 Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("RC2_k96b64_ECB_PKCS7 b1==b2", block1, block2);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k96b64_ECB_PKCS7 Decrypt", input, original);
- }
- public void TestRC2_k96b64_CBC_None ()
- {
- byte[] key = { 0x68, 0xC6, 0xF2, 0x13, 0xEA, 0x3D, 0x68, 0x09, 0xAC, 0x07, 0x21, 0x1F };
- byte[] iv = { 0x42, 0x47, 0xE6, 0x98, 0xF8, 0xFE, 0xCD, 0xFE };
- byte[] expected = { 0x7F, 0x9C, 0xCE, 0xC5, 0x2C, 0xB6, 0x60, 0xC3, 0xF3, 0x5F, 0x7E, 0x95, 0x6F, 0xFE, 0x8E, 0xC1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k96b64_CBC_None Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k96b64_CBC_None Decrypt", input, original);
- }
- public void TestRC2_k96b64_CBC_Zeros ()
- {
- byte[] key = { 0xDF, 0x00, 0x49, 0x93, 0xA1, 0x49, 0x50, 0x03, 0x52, 0x9C, 0x86, 0xF6 };
- byte[] iv = { 0x69, 0xFC, 0x72, 0xA2, 0x60, 0xF7, 0x4C, 0xB0 };
- byte[] expected = { 0x16, 0x07, 0x45, 0x07, 0xF8, 0xAE, 0xD3, 0xEA, 0x94, 0x1E, 0xC9, 0x1A, 0xEF, 0x8D, 0x3E, 0xF7, 0x88, 0x7D, 0x8D, 0xF8, 0xC6, 0x0A, 0xFA, 0x82 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k96b64_CBC_Zeros Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k96b64_CBC_Zeros Decrypt", input, original);
- }
- public void TestRC2_k96b64_CBC_PKCS7 ()
- {
- byte[] key = { 0x04, 0x2B, 0x2E, 0x98, 0x97, 0x84, 0x72, 0x0A, 0x78, 0x61, 0x02, 0xA9 };
- byte[] iv = { 0x16, 0x0A, 0x00, 0x48, 0xC3, 0x4F, 0x63, 0x05 };
- byte[] expected = { 0xD2, 0xC4, 0xC7, 0x02, 0xC7, 0xDB, 0xFB, 0xF6, 0xC1, 0x4D, 0x2D, 0x62, 0xF6, 0x57, 0x84, 0x84, 0xF2, 0x9B, 0x5C, 0x42, 0x66, 0x9B, 0x33, 0x1D };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k96b64_CBC_PKCS7 Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k96b64_CBC_PKCS7 Decrypt", input, original);
- }
- /* Invalid parameters RC2_k96b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters RC2_k96b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters RC2_k96b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
- public void TestRC2_k96b64_CFB8_None ()
- {
- byte[] key = { 0xDE, 0x6E, 0x40, 0xC3, 0x7D, 0x71, 0x0D, 0xCB, 0xA3, 0x62, 0x14, 0x76 };
- byte[] iv = { 0x72, 0x9E, 0xB4, 0xEE, 0x9B, 0x87, 0xAF, 0x12 };
- byte[] expected = { 0x14, 0x20, 0x3B, 0x35, 0xE2, 0x81, 0x84, 0x15, 0x6C, 0xA5, 0x4A, 0x94, 0xB3, 0xC0, 0x8D, 0x6A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CFB;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 64;
- algo.FeedbackSize = 8;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k96b64_CFB8_None Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k96b64_CFB8_None Decrypt", input, original);
- }
- public void TestRC2_k96b64_CFB8_Zeros ()
- {
- byte[] key = { 0xCF, 0x64, 0x81, 0x8F, 0x7D, 0x75, 0x8D, 0xB2, 0x9D, 0xE7, 0x39, 0xE3 };
- byte[] iv = { 0x30, 0xF2, 0x9E, 0x76, 0x96, 0x13, 0xCB, 0xDF };
- byte[] expected = { 0xC4, 0x0E, 0xE8, 0x61, 0x92, 0xB8, 0x9D, 0xDE, 0x0B, 0x39, 0x47, 0xD4, 0xD8, 0x05, 0x35, 0xF9, 0x0A, 0xAF, 0x63, 0x30, 0x4A, 0x82, 0x8C, 0xF2 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CFB;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 64;
- algo.FeedbackSize = 8;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k96b64_CFB8_Zeros Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k96b64_CFB8_Zeros Decrypt", input, original);
- }
- public void TestRC2_k96b64_CFB8_PKCS7 ()
- {
- byte[] key = { 0xC5, 0xF4, 0x44, 0xF2, 0xA0, 0xC3, 0xA7, 0x87, 0x64, 0x36, 0x5A, 0xFA };
- byte[] iv = { 0x20, 0xC5, 0x5E, 0x57, 0x5E, 0x0E, 0x2D, 0xDD };
- byte[] expected = { 0x66, 0x93, 0x1E, 0x15, 0x17, 0x5C, 0x3C, 0x07, 0xDB, 0x2F, 0xD9, 0x00, 0x0C, 0x3F, 0x9E, 0xBB, 0xB9, 0x32, 0xDD, 0x2D, 0x57, 0x69, 0x3D, 0xC3 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CFB;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 64;
- algo.FeedbackSize = 8;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k96b64_CFB8_PKCS7 Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k96b64_CFB8_PKCS7 Decrypt", input, original);
- }
- /* Invalid parameters RC2_k96b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters RC2_k96b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters RC2_k96b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
- public void TestRC2_k104b64_ECB_None ()
- {
- byte[] key = { 0x04, 0x5B, 0x99, 0xD3, 0xBC, 0x00, 0x27, 0xA3, 0xDC, 0x57, 0x4C, 0x82, 0xD6 };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0x70, 0x3D, 0xE7, 0xBC, 0x82, 0xFD, 0x8F, 0x03 };
- byte[] expected = { 0x5D, 0xEA, 0x9F, 0x1F, 0x19, 0xBB, 0x3D, 0x26, 0x5D, 0xEA, 0x9F, 0x1F, 0x19, 0xBB, 0x3D, 0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k104b64_ECB_None Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("RC2_k104b64_ECB_None b1==b2", block1, block2);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k104b64_ECB_None Decrypt", input, original);
- }
- public void TestRC2_k104b64_ECB_Zeros ()
- {
- byte[] key = { 0xA1, 0x3B, 0xDF, 0x6F, 0x6D, 0x2B, 0x7B, 0x0B, 0x13, 0x3E, 0x84, 0x35, 0x3C };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0xE6, 0x74, 0x41, 0xB6, 0xB4, 0x31, 0xB2, 0x6A };
- byte[] expected = { 0xAF, 0x46, 0x98, 0xF8, 0xC1, 0x4B, 0x45, 0x09, 0xAF, 0x46, 0x98, 0xF8, 0xC1, 0x4B, 0x45, 0x09, 0xAF, 0x46, 0x98, 0xF8, 0xC1, 0x4B, 0x45, 0x09 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k104b64_ECB_Zeros Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("RC2_k104b64_ECB_Zeros b1==b2", block1, block2);
- // also if padding is Zeros then all three blocks should be equals
- byte[] block3 = new byte[blockLength];
- Array.Copy (output, blockLength, block3, 0, blockLength);
- AssertEquals ("RC2_k104b64_ECB_Zeros b1==b3", block1, block3);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k104b64_ECB_Zeros Decrypt", input, original);
- }
- public void TestRC2_k104b64_ECB_PKCS7 ()
- {
- byte[] key = { 0x28, 0xDF, 0x8C, 0x1B, 0x7E, 0x04, 0xB2, 0x89, 0x72, 0xDA, 0x19, 0x57, 0x81 };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0xB8, 0x82, 0xA7, 0xBF, 0x99, 0xE9, 0x39, 0x02 };
- byte[] expected = { 0x5D, 0xEB, 0xD8, 0x26, 0x51, 0x86, 0xFB, 0x0E, 0x5D, 0xEB, 0xD8, 0x26, 0x51, 0x86, 0xFB, 0x0E, 0x1C, 0xFD, 0xE2, 0x77, 0xB6, 0x74, 0x55, 0x9C };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k104b64_ECB_PKCS7 Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("RC2_k104b64_ECB_PKCS7 b1==b2", block1, block2);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k104b64_ECB_PKCS7 Decrypt", input, original);
- }
- public void TestRC2_k104b64_CBC_None ()
- {
- byte[] key = { 0xF8, 0xCE, 0xA2, 0x33, 0xE5, 0x7D, 0x43, 0x72, 0xA9, 0xF5, 0xF1, 0x80, 0xBC };
- byte[] iv = { 0x12, 0xFF, 0x74, 0x3A, 0x36, 0x42, 0xBE, 0x78 };
- byte[] expected = { 0x64, 0xCD, 0x86, 0xA1, 0x1B, 0xB1, 0xD3, 0x9F, 0x8E, 0xFC, 0x42, 0xB8, 0x56, 0x96, 0x56, 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k104b64_CBC_None Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k104b64_CBC_None Decrypt", input, original);
- }
- public void TestRC2_k104b64_CBC_Zeros ()
- {
- byte[] key = { 0xEF, 0x4E, 0x02, 0x86, 0x5F, 0xE5, 0x94, 0x05, 0xEF, 0x8D, 0x8D, 0x5D, 0x04 };
- byte[] iv = { 0x98, 0x23, 0x93, 0xF7, 0x6D, 0x02, 0xB1, 0x73 };
- byte[] expected = { 0x50, 0x08, 0xAB, 0x8B, 0x26, 0x0D, 0x5B, 0x73, 0x3F, 0xE7, 0x75, 0x55, 0x4F, 0x9C, 0xDC, 0xFC, 0x17, 0x58, 0x2A, 0xB2, 0xFC, 0x54, 0x15, 0x97 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k104b64_CBC_Zeros Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k104b64_CBC_Zeros Decrypt", input, original);
- }
- public void TestRC2_k104b64_CBC_PKCS7 ()
- {
- byte[] key = { 0xE3, 0xD2, 0xC2, 0xA0, 0x54, 0xF5, 0xFC, 0xFC, 0x94, 0xA2, 0x6F, 0x6F, 0x52 };
- byte[] iv = { 0xBA, 0x5D, 0x0D, 0xBA, 0x0D, 0x0C, 0x4E, 0x5B };
- byte[] expected = { 0x6C, 0x5B, 0x74, 0x54, 0x0F, 0x86, 0x62, 0x06, 0x11, 0x65, 0xAA, 0x0B, 0x4F, 0x65, 0x34, 0x26, 0xAF, 0x26, 0x0D, 0xF4, 0xCE, 0xB6, 0xEE, 0xF0 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k104b64_CBC_PKCS7 Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k104b64_CBC_PKCS7 Decrypt", input, original);
- }
- /* Invalid parameters RC2_k104b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters RC2_k104b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters RC2_k104b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
- public void TestRC2_k104b64_CFB8_None ()
- {
- byte[] key = { 0xB3, 0xE2, 0x4D, 0x91, 0xE9, 0xF8, 0x72, 0xA4, 0x2E, 0x00, 0x0C, 0x08, 0x96 };
- byte[] iv = { 0x48, 0xF8, 0xDD, 0x61, 0xD5, 0x00, 0xD0, 0xE1 };
- byte[] expected = { 0xB9, 0xAA, 0x53, 0xD8, 0xCB, 0x23, 0xA6, 0x41, 0x69, 0x84, 0x2D, 0xD5, 0x4F, 0x45, 0xC2, 0x8D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CFB;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 64;
- algo.FeedbackSize = 8;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k104b64_CFB8_None Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k104b64_CFB8_None Decrypt", input, original);
- }
- public void TestRC2_k104b64_CFB8_Zeros ()
- {
- byte[] key = { 0xD4, 0x9C, 0x6B, 0x12, 0x41, 0x93, 0xEB, 0xDA, 0xDF, 0x7A, 0x81, 0x23, 0x1F };
- byte[] iv = { 0x3C, 0x0E, 0x48, 0xAA, 0xD8, 0x48, 0xE9, 0xC8 };
- byte[] expected = { 0x66, 0x39, 0x26, 0x0B, 0x81, 0xD8, 0x9A, 0x2F, 0xF1, 0x2C, 0xCF, 0x75, 0x8C, 0x01, 0x4D, 0x6E, 0x2A, 0x67, 0x9D, 0x0D, 0xA5, 0x56, 0x15, 0x41 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CFB;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 64;
- algo.FeedbackSize = 8;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k104b64_CFB8_Zeros Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k104b64_CFB8_Zeros Decrypt", input, original);
- }
- public void TestRC2_k104b64_CFB8_PKCS7 ()
- {
- byte[] key = { 0x2C, 0x38, 0x19, 0x43, 0x93, 0x38, 0x85, 0xC4, 0xF2, 0x19, 0xC7, 0x1B, 0x76 };
- byte[] iv = { 0xB4, 0x1B, 0x9C, 0x82, 0xB5, 0x6E, 0x42, 0xAF };
- byte[] expected = { 0xC5, 0x56, 0x04, 0x85, 0x0A, 0x52, 0x8B, 0x02, 0x69, 0xB6, 0xCF, 0xC7, 0xA9, 0x35, 0x63, 0xF7, 0x4B, 0x48, 0xF3, 0xD0, 0xFF, 0x74, 0xA7, 0xB5 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CFB;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 64;
- algo.FeedbackSize = 8;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k104b64_CFB8_PKCS7 Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k104b64_CFB8_PKCS7 Decrypt", input, original);
- }
- /* Invalid parameters RC2_k104b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters RC2_k104b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters RC2_k104b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
- public void TestRC2_k112b64_ECB_None ()
- {
- byte[] key = { 0xB7, 0x95, 0xA4, 0x42, 0x21, 0x3D, 0x30, 0x51, 0x98, 0x01, 0xA0, 0x6C, 0x45, 0x68 };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0x3B, 0x36, 0x51, 0x24, 0xF4, 0x1A, 0xC1, 0x91 };
- byte[] expected = { 0x31, 0xAE, 0xBA, 0xFB, 0xB4, 0xFA, 0x78, 0x30, 0x31, 0xAE, 0xBA, 0xFB, 0xB4, 0xFA, 0x78, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k112b64_ECB_None Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("RC2_k112b64_ECB_None b1==b2", block1, block2);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k112b64_ECB_None Decrypt", input, original);
- }
- public void TestRC2_k112b64_ECB_Zeros ()
- {
- byte[] key = { 0xB1, 0x8E, 0x09, 0xFB, 0x70, 0x03, 0x6A, 0xF2, 0xCF, 0x9D, 0x9B, 0xD7, 0x10, 0xD4 };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0x64, 0x15, 0x78, 0xB8, 0x25, 0x15, 0xFA, 0xC8 };
- byte[] expected = { 0xB1, 0xC2, 0x27, 0xA8, 0x32, 0xBA, 0x34, 0x06, 0xB1, 0xC2, 0x27, 0xA8, 0x32, 0xBA, 0x34, 0x06, 0xB1, 0xC2, 0x27, 0xA8, 0x32, 0xBA, 0x34, 0x06 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k112b64_ECB_Zeros Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("RC2_k112b64_ECB_Zeros b1==b2", block1, block2);
- // also if padding is Zeros then all three blocks should be equals
- byte[] block3 = new byte[blockLength];
- Array.Copy (output, blockLength, block3, 0, blockLength);
- AssertEquals ("RC2_k112b64_ECB_Zeros b1==b3", block1, block3);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k112b64_ECB_Zeros Decrypt", input, original);
- }
- public void TestRC2_k112b64_ECB_PKCS7 ()
- {
- byte[] key = { 0x4F, 0xE8, 0x2C, 0x62, 0x98, 0x89, 0xEF, 0x11, 0x29, 0xB2, 0xDD, 0x4D, 0xE1, 0x39 };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0x15, 0xE0, 0x95, 0x29, 0xEB, 0xE5, 0xC7, 0x8E };
- byte[] expected = { 0x43, 0x79, 0x6E, 0xCF, 0x63, 0x68, 0xF0, 0x55, 0x43, 0x79, 0x6E, 0xCF, 0x63, 0x68, 0xF0, 0x55, 0x80, 0x64, 0x15, 0x36, 0x08, 0xD0, 0x76, 0x58 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k112b64_ECB_PKCS7 Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("RC2_k112b64_ECB_PKCS7 b1==b2", block1, block2);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k112b64_ECB_PKCS7 Decrypt", input, original);
- }
- public void TestRC2_k112b64_CBC_None ()
- {
- byte[] key = { 0xC0, 0x04, 0xA9, 0x3C, 0x94, 0xA1, 0x78, 0xA2, 0x4B, 0x94, 0x6F, 0x19, 0xD1, 0xE1 };
- byte[] iv = { 0x28, 0x94, 0x16, 0x28, 0x69, 0x64, 0xF6, 0x83 };
- byte[] expected = { 0xB7, 0x2F, 0x20, 0x02, 0xAD, 0x97, 0x21, 0x45, 0xDA, 0xC2, 0x0D, 0xD9, 0xEB, 0xCC, 0xA0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k112b64_CBC_None Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k112b64_CBC_None Decrypt", input, original);
- }
- public void TestRC2_k112b64_CBC_Zeros ()
- {
- byte[] key = { 0x59, 0xFF, 0xC2, 0xB5, 0x62, 0x84, 0x27, 0x49, 0x4B, 0xFF, 0xFF, 0xCE, 0xBB, 0xBD };
- byte[] iv = { 0x2E, 0x9E, 0xD3, 0xF6, 0xFC, 0xD7, 0xC6, 0x1C };
- byte[] expected = { 0x38, 0xE4, 0x4D, 0xD5, 0x3F, 0x74, 0x44, 0x90, 0x11, 0xCD, 0x6E, 0x13, 0x7A, 0x9A, 0x82, 0xBB, 0xBD, 0xD1, 0x0F, 0x38, 0x0F, 0x5F, 0x97, 0x14 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k112b64_CBC_Zeros Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k112b64_CBC_Zeros Decrypt", input, original);
- }
- public void TestRC2_k112b64_CBC_PKCS7 ()
- {
- byte[] key = { 0xE4, 0x49, 0xA4, 0xBE, 0x30, 0xE1, 0xB5, 0x21, 0x33, 0xC6, 0x37, 0x88, 0x30, 0xEC };
- byte[] iv = { 0x74, 0xAC, 0x28, 0x92, 0xA5, 0xF1, 0x31, 0xC9 };
- byte[] expected = { 0xE5, 0x7B, 0x53, 0x65, 0x37, 0xD8, 0x29, 0xBD, 0x4B, 0x73, 0x3B, 0x1B, 0x5B, 0x00, 0x04, 0xE2, 0x11, 0x5B, 0x24, 0x6F, 0x6D, 0x7F, 0x1C, 0xE8 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k112b64_CBC_PKCS7 Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k112b64_CBC_PKCS7 Decrypt", input, original);
- }
- /* Invalid parameters RC2_k112b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters RC2_k112b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters RC2_k112b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
- public void TestRC2_k112b64_CFB8_None ()
- {
- byte[] key = { 0x70, 0x12, 0xEC, 0xAB, 0x6E, 0x1D, 0xEF, 0x51, 0xEE, 0xA8, 0x81, 0xE1, 0x21, 0xFF };
- byte[] iv = { 0x0E, 0x56, 0xA2, 0xA3, 0x8C, 0x5D, 0x9C, 0x1F };
- byte[] expected = { 0x71, 0x1C, 0x76, 0xB1, 0x61, 0x32, 0x77, 0xB7, 0x98, 0x42, 0x31, 0xF1, 0x0A, 0xE4, 0xC3, 0x83, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CFB;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 64;
- algo.FeedbackSize = 8;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k112b64_CFB8_None Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k112b64_CFB8_None Decrypt", input, original);
- }
- public void TestRC2_k112b64_CFB8_Zeros ()
- {
- byte[] key = { 0x48, 0x66, 0x16, 0xD6, 0x57, 0xBF, 0x38, 0xB7, 0x22, 0x81, 0x9F, 0x75, 0xE0, 0x88 };
- byte[] iv = { 0x51, 0x2C, 0x6A, 0x59, 0xAB, 0xD2, 0xAE, 0x6E };
- byte[] expected = { 0xF1, 0x9E, 0x85, 0x7A, 0x7D, 0xF0, 0x39, 0x0D, 0x11, 0x47, 0x11, 0xC0, 0x1A, 0x19, 0x21, 0x85, 0x95, 0x40, 0xDA, 0x4A, 0xEE, 0x49, 0xC7, 0x54 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CFB;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 64;
- algo.FeedbackSize = 8;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k112b64_CFB8_Zeros Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k112b64_CFB8_Zeros Decrypt", input, original);
- }
- public void TestRC2_k112b64_CFB8_PKCS7 ()
- {
- byte[] key = { 0x55, 0x20, 0xA1, 0xD8, 0xFA, 0xE7, 0x0D, 0xF9, 0xB6, 0x4B, 0x90, 0x10, 0xDE, 0xB1 };
- byte[] iv = { 0x26, 0x6C, 0xB0, 0xB4, 0x4D, 0x7F, 0x5C, 0x18 };
- byte[] expected = { 0xC8, 0x00, 0x9F, 0x21, 0x2C, 0xB0, 0x75, 0x6C, 0x62, 0xD8, 0xD0, 0x30, 0x11, 0x93, 0x73, 0x2F, 0xC5, 0xBC, 0xB1, 0xED, 0x2E, 0xBE, 0xCF, 0xBC };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CFB;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 64;
- algo.FeedbackSize = 8;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k112b64_CFB8_PKCS7 Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k112b64_CFB8_PKCS7 Decrypt", input, original);
- }
- /* Invalid parameters RC2_k112b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters RC2_k112b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters RC2_k112b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
- public void TestRC2_k120b64_ECB_None ()
- {
- byte[] key = { 0x5D, 0x08, 0xC7, 0xB8, 0xB1, 0xEB, 0x89, 0x1C, 0xC0, 0x3F, 0xE6, 0x2F, 0xC4, 0x79, 0x11 };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0x76, 0x1C, 0xAC, 0x0F, 0x39, 0x6C, 0x1A, 0x44 };
- byte[] expected = { 0xA4, 0xC1, 0x60, 0x59, 0x6B, 0x45, 0xE0, 0x4C, 0xA4, 0xC1, 0x60, 0x59, 0x6B, 0x45, 0xE0, 0x4C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k120b64_ECB_None Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("RC2_k120b64_ECB_None b1==b2", block1, block2);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k120b64_ECB_None Decrypt", input, original);
- }
- public void TestRC2_k120b64_ECB_Zeros ()
- {
- byte[] key = { 0x1D, 0x13, 0x51, 0x02, 0x28, 0xF4, 0xF0, 0x13, 0x90, 0xFD, 0xE4, 0xC0, 0xE5, 0x57, 0x9A };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0x9E, 0xC9, 0xA7, 0x52, 0xD2, 0x6E, 0x9B, 0xE4 };
- byte[] expected = { 0x23, 0x58, 0x1C, 0x66, 0x7D, 0x2F, 0x71, 0x4F, 0x23, 0x58, 0x1C, 0x66, 0x7D, 0x2F, 0x71, 0x4F, 0x23, 0x58, 0x1C, 0x66, 0x7D, 0x2F, 0x71, 0x4F };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k120b64_ECB_Zeros Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("RC2_k120b64_ECB_Zeros b1==b2", block1, block2);
- // also if padding is Zeros then all three blocks should be equals
- byte[] block3 = new byte[blockLength];
- Array.Copy (output, blockLength, block3, 0, blockLength);
- AssertEquals ("RC2_k120b64_ECB_Zeros b1==b3", block1, block3);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k120b64_ECB_Zeros Decrypt", input, original);
- }
- public void TestRC2_k120b64_ECB_PKCS7 ()
- {
- byte[] key = { 0x23, 0xF2, 0xFB, 0x09, 0xC1, 0xEF, 0xC1, 0xFF, 0x16, 0xFF, 0x60, 0xC1, 0x3A, 0x94, 0x3E };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0xB6, 0x10, 0xE3, 0xE9, 0x24, 0x03, 0xCA, 0xAA };
- byte[] expected = { 0x92, 0xF3, 0xF0, 0x81, 0x13, 0x40, 0x19, 0x61, 0x92, 0xF3, 0xF0, 0x81, 0x13, 0x40, 0x19, 0x61, 0x36, 0xCC, 0xEC, 0x80, 0xF6, 0xF4, 0xCC, 0xB7 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k120b64_ECB_PKCS7 Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("RC2_k120b64_ECB_PKCS7 b1==b2", block1, block2);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k120b64_ECB_PKCS7 Decrypt", input, original);
- }
- public void TestRC2_k120b64_CBC_None ()
- {
- byte[] key = { 0x12, 0x43, 0xEE, 0x74, 0xE8, 0x4E, 0x3A, 0xF7, 0x24, 0x58, 0x10, 0xC9, 0x41, 0x7E, 0x46 };
- byte[] iv = { 0x7B, 0x57, 0x22, 0x19, 0xFB, 0x30, 0xED, 0x48 };
- byte[] expected = { 0x75, 0xB0, 0x41, 0x19, 0x7F, 0x80, 0x91, 0x4A, 0xCD, 0x03, 0x41, 0x59, 0xE4, 0xC0, 0x92, 0xE7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k120b64_CBC_None Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k120b64_CBC_None Decrypt", input, original);
- }
- public void TestRC2_k120b64_CBC_Zeros ()
- {
- byte[] key = { 0x2A, 0xCC, 0xFF, 0xD0, 0x46, 0xAF, 0x74, 0xB2, 0x0E, 0x64, 0xBD, 0xE9, 0x6D, 0xC5, 0xE8 };
- byte[] iv = { 0x10, 0x21, 0xE3, 0xCB, 0x46, 0x02, 0x33, 0x4F };
- byte[] expected = { 0x88, 0x71, 0x0D, 0x01, 0xE9, 0xD3, 0xC7, 0x3F, 0x7E, 0xCA, 0xA7, 0x9A, 0x2D, 0x95, 0xC6, 0xED, 0xDA, 0xAA, 0xE9, 0x23, 0x01, 0x70, 0x6E, 0x59 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k120b64_CBC_Zeros Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k120b64_CBC_Zeros Decrypt", input, original);
- }
- public void TestRC2_k120b64_CBC_PKCS7 ()
- {
- byte[] key = { 0xE8, 0xE8, 0x44, 0x9D, 0xEA, 0x33, 0x10, 0xCB, 0xEA, 0xEF, 0x69, 0x94, 0xE4, 0x31, 0xF0 };
- byte[] iv = { 0xC7, 0x0F, 0xE1, 0x79, 0x2B, 0x57, 0x5D, 0xA7 };
- byte[] expected = { 0x7E, 0x1F, 0xD6, 0xCF, 0xB1, 0xAE, 0xC0, 0x2C, 0xD6, 0x02, 0x01, 0x62, 0x77, 0x95, 0x02, 0xE8, 0x8D, 0xEC, 0x8D, 0xCC, 0xB2, 0x6B, 0x92, 0x7A };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k120b64_CBC_PKCS7 Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k120b64_CBC_PKCS7 Decrypt", input, original);
- }
- /* Invalid parameters RC2_k120b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters RC2_k120b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters RC2_k120b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
- public void TestRC2_k120b64_CFB8_None ()
- {
- byte[] key = { 0x0F, 0x0D, 0x1F, 0x09, 0xC2, 0xEA, 0xC5, 0xFE, 0xD1, 0x5A, 0x4C, 0x39, 0x2E, 0x62, 0xED };
- byte[] iv = { 0xCA, 0x90, 0x74, 0xAD, 0x6B, 0xD5, 0x42, 0xCF };
- byte[] expected = { 0xEB, 0xC3, 0xF4, 0x08, 0xCF, 0x11, 0x3E, 0xC4, 0x98, 0x8A, 0xAB, 0x6F, 0xEE, 0x32, 0xFC, 0x2B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CFB;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 64;
- algo.FeedbackSize = 8;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k120b64_CFB8_None Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k120b64_CFB8_None Decrypt", input, original);
- }
- public void TestRC2_k120b64_CFB8_Zeros ()
- {
- byte[] key = { 0xDA, 0xAD, 0xD7, 0xFB, 0x36, 0x64, 0x3B, 0xE8, 0x35, 0x64, 0xC8, 0xAF, 0x0D, 0xB3, 0xAC };
- byte[] iv = { 0x6B, 0x99, 0x8D, 0xCA, 0x51, 0xD8, 0x26, 0x48 };
- byte[] expected = { 0xDE, 0xED, 0xF4, 0xA8, 0x9D, 0x5C, 0xCE, 0x22, 0x7A, 0xD5, 0x1B, 0x3F, 0x89, 0x6E, 0x91, 0x61, 0xE1, 0x44, 0x1E, 0x5C, 0xFA, 0xC1, 0x40, 0x97 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CFB;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 64;
- algo.FeedbackSize = 8;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k120b64_CFB8_Zeros Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k120b64_CFB8_Zeros Decrypt", input, original);
- }
- public void TestRC2_k120b64_CFB8_PKCS7 ()
- {
- byte[] key = { 0x26, 0xA9, 0xE5, 0xE2, 0xE4, 0x48, 0xB5, 0x9F, 0xAC, 0x3E, 0x77, 0xB0, 0xEF, 0x1B, 0x00 };
- byte[] iv = { 0x0E, 0x98, 0x7F, 0xC4, 0xAC, 0x08, 0x94, 0x03 };
- byte[] expected = { 0xAD, 0xEC, 0xD6, 0x71, 0xDF, 0x36, 0x69, 0x80, 0xE6, 0x74, 0x79, 0xC2, 0xE0, 0xDF, 0xCF, 0xD8, 0xB4, 0x3A, 0x22, 0x6F, 0x41, 0xAD, 0x77, 0x4D };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CFB;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 64;
- algo.FeedbackSize = 8;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k120b64_CFB8_PKCS7 Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k120b64_CFB8_PKCS7 Decrypt", input, original);
- }
- /* Invalid parameters RC2_k120b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters RC2_k120b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters RC2_k120b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
- public void TestRC2_k128b64_ECB_None ()
- {
- byte[] key = { 0x4F, 0x02, 0xB1, 0xA6, 0x5E, 0xAE, 0xB9, 0x0C, 0x3A, 0x96, 0xFF, 0x62, 0x90, 0x9A, 0xD8, 0x1B };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0xC7, 0x89, 0x19, 0x4F, 0x3C, 0xC3, 0x05, 0x83 };
- byte[] expected = { 0xC8, 0x83, 0x4D, 0xE2, 0x6A, 0xFA, 0x75, 0x41, 0xC8, 0x83, 0x4D, 0xE2, 0x6A, 0xFA, 0x75, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k128b64_ECB_None Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("RC2_k128b64_ECB_None b1==b2", block1, block2);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k128b64_ECB_None Decrypt", input, original);
- }
- public void TestRC2_k128b64_ECB_Zeros ()
- {
- byte[] key = { 0x45, 0xBE, 0xD8, 0x8E, 0x0A, 0xE7, 0xF9, 0xE2, 0x3C, 0x33, 0xE7, 0x93, 0xD4, 0x9D, 0xAE, 0x2B };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0x83, 0x27, 0x57, 0x97, 0x06, 0x4F, 0xFE, 0xB3 };
- byte[] expected = { 0x28, 0x59, 0x45, 0xF6, 0x5E, 0x4F, 0x97, 0xF3, 0x28, 0x59, 0x45, 0xF6, 0x5E, 0x4F, 0x97, 0xF3, 0x28, 0x59, 0x45, 0xF6, 0x5E, 0x4F, 0x97, 0xF3 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k128b64_ECB_Zeros Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("RC2_k128b64_ECB_Zeros b1==b2", block1, block2);
- // also if padding is Zeros then all three blocks should be equals
- byte[] block3 = new byte[blockLength];
- Array.Copy (output, blockLength, block3, 0, blockLength);
- AssertEquals ("RC2_k128b64_ECB_Zeros b1==b3", block1, block3);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k128b64_ECB_Zeros Decrypt", input, original);
- }
- public void TestRC2_k128b64_ECB_PKCS7 ()
- {
- byte[] key = { 0x6F, 0x04, 0x76, 0x7D, 0x88, 0x01, 0x29, 0x6A, 0xD5, 0x1E, 0x38, 0x9D, 0xED, 0x56, 0xAC, 0x9C };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0x82, 0x74, 0xAC, 0xAA, 0x42, 0x29, 0x35, 0x8D };
- byte[] expected = { 0xCB, 0xE5, 0xBB, 0xCC, 0x99, 0x8D, 0x1D, 0xA6, 0xCB, 0xE5, 0xBB, 0xCC, 0x99, 0x8D, 0x1D, 0xA6, 0x5B, 0x35, 0x28, 0xE7, 0xAC, 0xFE, 0xF0, 0xD1 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k128b64_ECB_PKCS7 Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("RC2_k128b64_ECB_PKCS7 b1==b2", block1, block2);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k128b64_ECB_PKCS7 Decrypt", input, original);
- }
- public void TestRC2_k128b64_CBC_None ()
- {
- byte[] key = { 0x17, 0x3F, 0x40, 0xF3, 0xDC, 0xFF, 0x8F, 0xF2, 0x71, 0x2E, 0x8B, 0x6A, 0xE0, 0x2E, 0x3F, 0x82 };
- byte[] iv = { 0xFA, 0xB4, 0x41, 0x91, 0x34, 0xFC, 0x9B, 0x49 };
- byte[] expected = { 0x05, 0x1B, 0x27, 0x78, 0xF0, 0x3D, 0xC4, 0x77, 0x9E, 0x59, 0x27, 0xEC, 0x2D, 0x1D, 0x7F, 0x56, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k128b64_CBC_None Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k128b64_CBC_None Decrypt", input, original);
- }
- public void TestRC2_k128b64_CBC_Zeros ()
- {
- byte[] key = { 0x49, 0x89, 0x3E, 0x29, 0xCB, 0xB9, 0x06, 0x85, 0x7F, 0x8B, 0x86, 0xEB, 0xD7, 0x47, 0x91, 0x1D };
- byte[] iv = { 0xCB, 0xA1, 0x0F, 0x53, 0x7B, 0x71, 0x04, 0x89 };
- byte[] expected = { 0x17, 0x58, 0xD1, 0xF4, 0x1E, 0x58, 0xB0, 0x10, 0x31, 0x17, 0x40, 0x3F, 0x40, 0x22, 0x75, 0x32, 0x4F, 0xDE, 0x64, 0xE0, 0x66, 0xF4, 0xF7, 0xA0 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k128b64_CBC_Zeros Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k128b64_CBC_Zeros Decrypt", input, original);
- }
- public void TestRC2_k128b64_CBC_PKCS7 ()
- {
- byte[] key = { 0x22, 0x04, 0xDB, 0x15, 0xD6, 0x2E, 0xEF, 0x6D, 0x5D, 0x6A, 0xDA, 0x55, 0x67, 0x41, 0x4E, 0xFD };
- byte[] iv = { 0xB8, 0xD1, 0xD8, 0x23, 0x00, 0x39, 0x89, 0x83 };
- byte[] expected = { 0xC8, 0x4F, 0xCC, 0x05, 0x7F, 0x44, 0x49, 0xBE, 0x73, 0x78, 0xE8, 0x7B, 0xD9, 0xB1, 0x56, 0xC3, 0x37, 0x1E, 0xBE, 0x4D, 0x2B, 0x2F, 0xC7, 0x9E };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k128b64_CBC_PKCS7 Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k128b64_CBC_PKCS7 Decrypt", input, original);
- }
- /* Invalid parameters RC2_k128b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters RC2_k128b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters RC2_k128b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
- public void TestRC2_k128b64_CFB8_None ()
- {
- byte[] key = { 0x61, 0x93, 0x31, 0x3A, 0xC2, 0x9B, 0x53, 0xB1, 0x26, 0x64, 0x36, 0x03, 0x16, 0x4A, 0xE3, 0x99 };
- byte[] iv = { 0xDD, 0xAD, 0xA4, 0x57, 0xC1, 0x21, 0xF1, 0xA8 };
- byte[] expected = { 0x94, 0xD9, 0x62, 0x83, 0x80, 0x4C, 0x91, 0x90, 0x63, 0x41, 0xBC, 0xBD, 0x8B, 0x7F, 0xD9, 0xB1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CFB;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 64;
- algo.FeedbackSize = 8;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k128b64_CFB8_None Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k128b64_CFB8_None Decrypt", input, original);
- }
- public void TestRC2_k128b64_CFB8_Zeros ()
- {
- byte[] key = { 0x64, 0x09, 0x9A, 0xF0, 0xD2, 0x52, 0x8C, 0x03, 0xF3, 0xBF, 0x1B, 0x9B, 0x92, 0x0E, 0xBA, 0x33 };
- byte[] iv = { 0x15, 0x64, 0xE4, 0xFA, 0xFA, 0x58, 0x54, 0x7B };
- byte[] expected = { 0xC8, 0x8F, 0xCC, 0x77, 0xA3, 0x82, 0x31, 0xD4, 0x7A, 0x68, 0x05, 0x8F, 0xF2, 0x1B, 0x9E, 0xCC, 0xDA, 0x6F, 0x74, 0x1D, 0x43, 0xE0, 0x90, 0x8B };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CFB;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 64;
- algo.FeedbackSize = 8;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k128b64_CFB8_Zeros Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k128b64_CFB8_Zeros Decrypt", input, original);
- }
- public void TestRC2_k128b64_CFB8_PKCS7 ()
- {
- byte[] key = { 0x1F, 0x09, 0xF8, 0x1B, 0xA9, 0xA4, 0x70, 0x8D, 0x53, 0x76, 0x19, 0x4A, 0xAA, 0x62, 0x84, 0x94 };
- byte[] iv = { 0xCC, 0x7B, 0xBE, 0xE9, 0xEE, 0x8E, 0x9C, 0x02 };
- byte[] expected = { 0xA7, 0x1B, 0xD5, 0x4E, 0xDB, 0xF7, 0x84, 0xC2, 0xAA, 0x89, 0xAA, 0x3C, 0x3A, 0x63, 0x8A, 0xB2, 0xEF, 0x0C, 0x5B, 0xB0, 0xF4, 0xD9, 0x0A, 0x46 };
- SymmetricAlgorithm algo = RC2.Create ();
- algo.Mode = CipherMode.CFB;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 64;
- algo.FeedbackSize = 8;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("RC2_k128b64_CFB8_PKCS7 Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("RC2_k128b64_CFB8_PKCS7 Decrypt", input, original);
- }
- /* Invalid parameters RC2_k128b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters RC2_k128b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters RC2_k128b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
- public void TestRijndael_k128b128_ECB_None ()
- {
- byte[] key = { 0xAF, 0x4D, 0xFE, 0x58, 0x33, 0xAC, 0x91, 0xB2, 0xFA, 0xA3, 0x96, 0x54, 0x0B, 0x68, 0xDD, 0xA1 };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0xAF, 0x70, 0xC2, 0x2E, 0x2D, 0xF1, 0x0D, 0x7F, 0x52, 0xF4, 0x65, 0x79, 0x78, 0xAC, 0x80, 0xEF };
- byte[] expected = { 0x6D, 0xC2, 0x4A, 0x51, 0x2D, 0xAB, 0x67, 0xCB, 0xD8, 0xD4, 0xD5, 0xE6, 0x0B, 0x24, 0x02, 0x90, 0x6D, 0xC2, 0x4A, 0x51, 0x2D, 0xAB, 0x67, 0xCB, 0xD8, 0xD4, 0xD5, 0xE6, 0x0B, 0x24, 0x02, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 128;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("Rijndael_k128b128_ECB_None Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("Rijndael_k128b128_ECB_None b1==b2", block1, block2);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("Rijndael_k128b128_ECB_None Decrypt", input, original);
- }
- public void TestRijndael_k128b128_ECB_Zeros ()
- {
- byte[] key = { 0xA4, 0x39, 0x01, 0x00, 0xDB, 0x0A, 0x47, 0xD8, 0xD8, 0xDC, 0x01, 0xF4, 0xBE, 0x96, 0xF4, 0xBB };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0xEA, 0xBD, 0x55, 0x85, 0x3F, 0xC1, 0x5F, 0xCB, 0x06, 0x26, 0x3F, 0x88, 0x6A, 0x2D, 0x69, 0x45 };
- byte[] expected = { 0x19, 0x32, 0x7E, 0x79, 0xE3, 0xC1, 0xFE, 0xA0, 0xFD, 0x26, 0x27, 0x61, 0xC0, 0xB8, 0x06, 0xC2, 0x19, 0x32, 0x7E, 0x79, 0xE3, 0xC1, 0xFE, 0xA0, 0xFD, 0x26, 0x27, 0x61, 0xC0, 0xB8, 0x06, 0xC2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 128;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- // some exception can be normal... other not so!
- try {
- Encrypt (encryptor, input, output);
- }
- catch (Exception e) {
- if (e.Message != "Input buffer contains insufficient data. ")
- Fail ("Rijndael_k128b128_ECB_Zeros: This isn't the expected exception: " + e.ToString ());
- }
- }
- public void TestRijndael_k128b128_ECB_PKCS7 ()
- {
- byte[] key = { 0x5C, 0x58, 0x03, 0x1D, 0x05, 0x07, 0xDE, 0x93, 0x8D, 0x85, 0xFD, 0x50, 0x68, 0xA3, 0xD7, 0x6B };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0x1C, 0x32, 0xFE, 0x99, 0x95, 0x16, 0x74, 0xC0, 0x6F, 0xE6, 0x01, 0x2C, 0x1F, 0x07, 0x54, 0xE8 };
- byte[] expected = { 0xEE, 0x1C, 0x0B, 0x2F, 0x1E, 0xCE, 0x69, 0xBC, 0xEA, 0xF6, 0xED, 0xA9, 0xF0, 0xE3, 0xE7, 0xC3, 0xEE, 0x1C, 0x0B, 0x2F, 0x1E, 0xCE, 0x69, 0xBC, 0xEA, 0xF6, 0xED, 0xA9, 0xF0, 0xE3, 0xE7, 0xC3, 0x2E, 0xB4, 0x6F, 0x8C, 0xD3, 0x37, 0xF4, 0x8E, 0x6D, 0x08, 0x35, 0x47, 0xD1, 0x1A, 0xB2, 0xA0 };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 128;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("Rijndael_k128b128_ECB_PKCS7 Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("Rijndael_k128b128_ECB_PKCS7 b1==b2", block1, block2);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("Rijndael_k128b128_ECB_PKCS7 Decrypt", input, original);
- }
- public void TestRijndael_k128b128_CBC_None ()
- {
- byte[] key = { 0xED, 0xE4, 0xD9, 0x97, 0x8E, 0x5C, 0xF8, 0x86, 0xFE, 0x6B, 0xF4, 0xA7, 0x26, 0xDA, 0x70, 0x47 };
- byte[] iv = { 0x06, 0xE1, 0xA5, 0x97, 0x7E, 0x20, 0x0C, 0x47, 0xA4, 0xAF, 0xB8, 0xF3, 0x8D, 0x2E, 0xA9, 0xAC };
- byte[] expected = { 0xB1, 0x73, 0xDA, 0x05, 0x4C, 0x0D, 0x6C, 0x5D, 0x60, 0x72, 0x76, 0x79, 0x64, 0xA6, 0x45, 0x89, 0xA5, 0xCD, 0x35, 0x2C, 0x56, 0x12, 0x7D, 0xA6, 0x84, 0x36, 0xEB, 0xCC, 0xDF, 0x5C, 0xCB, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 128;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("Rijndael_k128b128_CBC_None Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("Rijndael_k128b128_CBC_None Decrypt", input, original);
- }
- public void TestRijndael_k128b128_CBC_Zeros ()
- {
- byte[] key = { 0x7F, 0x03, 0x95, 0x4E, 0x42, 0x9E, 0x83, 0x85, 0x4B, 0x1A, 0x87, 0x36, 0xA1, 0x5B, 0xA8, 0x24 };
- byte[] iv = { 0x75, 0x49, 0x7B, 0xBE, 0x78, 0x55, 0x5F, 0xE9, 0x67, 0xCB, 0x7E, 0x30, 0x71, 0xD1, 0x36, 0x49 };
- byte[] expected = { 0xC8, 0xE2, 0xE5, 0x14, 0x17, 0x10, 0x14, 0xA5, 0x14, 0x8E, 0x59, 0x82, 0x7C, 0x92, 0x12, 0x91, 0x49, 0xE4, 0x24, 0x2C, 0x38, 0x98, 0x91, 0x0B, 0xD8, 0x5C, 0xD0, 0x79, 0xCD, 0x35, 0x85, 0x6B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 128;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- // some exception can be normal... other not so!
- try {
- Encrypt (encryptor, input, output);
- }
- catch (Exception e) {
- if (e.Message != "Input buffer contains insufficient data. ")
- Fail ("Rijndael_k128b128_CBC_Zeros: This isn't the expected exception: " + e.ToString ());
- }
- }
- public void TestRijndael_k128b128_CBC_PKCS7 ()
- {
- byte[] key = { 0x02, 0xE6, 0xC1, 0xE2, 0x7E, 0x89, 0xB9, 0x04, 0xE7, 0x9A, 0xB8, 0x83, 0xA4, 0xF8, 0x1B, 0x64 };
- byte[] iv = { 0xBC, 0xE4, 0x47, 0x1E, 0xD0, 0xDD, 0x09, 0x0D, 0xFC, 0xA1, 0x44, 0xCD, 0x88, 0x92, 0x41, 0xA5 };
- byte[] expected = { 0xEA, 0xB3, 0x9D, 0xCC, 0xE6, 0x74, 0x22, 0xE5, 0x15, 0xEE, 0x1C, 0xA9, 0x48, 0xB9, 0x55, 0x01, 0xEA, 0x9F, 0x98, 0x8D, 0x5D, 0x59, 0xB1, 0x1C, 0xEC, 0xE5, 0x68, 0xEE, 0x86, 0x22, 0x17, 0xBA, 0x95, 0x7D, 0xEC, 0x06, 0x4B, 0x48, 0x90, 0x0E, 0x75, 0x38, 0xC0, 0x28, 0x7D, 0x72, 0x32, 0xF8 };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 128;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("Rijndael_k128b128_CBC_PKCS7 Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("Rijndael_k128b128_CBC_PKCS7 Decrypt", input, original);
- }
- /* Invalid parameters Rijndael_k128b128_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters Rijndael_k128b128_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters Rijndael_k128b128_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters Rijndael_k128b128_CFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters Rijndael_k128b128_CFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters Rijndael_k128b128_CFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters Rijndael_k128b128_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters Rijndael_k128b128_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters Rijndael_k128b128_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
- public void TestRijndael_k128b192_ECB_None ()
- {
- byte[] key = { 0xA5, 0x7F, 0xA2, 0x9F, 0xDA, 0xEE, 0x56, 0x2E, 0xF9, 0x3A, 0xEE, 0x1E, 0x30, 0x46, 0x80, 0x66 };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0x81, 0xE8, 0x4F, 0x8A, 0xFC, 0xD0, 0x12, 0xB3, 0xF8, 0x1F, 0x30, 0xE2, 0x40, 0x90, 0xFB, 0x96, 0x88, 0xC0, 0xC8, 0xF7, 0x4A, 0x3E, 0xC0, 0x73 };
- byte[] expected = { 0xC1, 0xC5, 0x13, 0x1B, 0x11, 0x93, 0x52, 0xE6, 0x4A, 0xA3, 0xF8, 0xE7, 0x28, 0xDE, 0x02, 0x9A, 0x5D, 0x2B, 0x14, 0x6A, 0x5D, 0x0F, 0x24, 0x8F, 0xC1, 0xC5, 0x13, 0x1B, 0x11, 0x93, 0x52, 0xE6, 0x4A, 0xA3, 0xF8, 0xE7, 0x28, 0xDE, 0x02, 0x9A, 0x5D, 0x2B, 0x14, 0x6A, 0x5D, 0x0F, 0x24, 0x8F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 192;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("Rijndael_k128b192_ECB_None Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("Rijndael_k128b192_ECB_None b1==b2", block1, block2);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("Rijndael_k128b192_ECB_None Decrypt", input, original);
- }
- public void TestRijndael_k128b192_ECB_Zeros ()
- {
- byte[] key = { 0xDF, 0x1B, 0x73, 0xA3, 0xE3, 0x53, 0x75, 0x92, 0x2B, 0xD0, 0x44, 0x35, 0x94, 0xF5, 0xB2, 0xE7 };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0x21, 0x82, 0x61, 0x4A, 0x57, 0xC0, 0x7D, 0x96, 0xFF, 0xC2, 0x08, 0xC1, 0x6C, 0xDF, 0x7C, 0x65, 0xC1, 0x8B, 0xFE, 0x5E, 0xD5, 0x82, 0xAD, 0x98 };
- byte[] expected = { 0xC9, 0x4E, 0xE0, 0x8F, 0x95, 0x55, 0x52, 0x1A, 0x75, 0xA9, 0x92, 0x1D, 0xFA, 0x30, 0xBD, 0xB8, 0x55, 0xA7, 0x8B, 0xF9, 0x58, 0xE9, 0x1B, 0x4C, 0xC9, 0x4E, 0xE0, 0x8F, 0x95, 0x55, 0x52, 0x1A, 0x75, 0xA9, 0x92, 0x1D, 0xFA, 0x30, 0xBD, 0xB8, 0x55, 0xA7, 0x8B, 0xF9, 0x58, 0xE9, 0x1B, 0x4C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 192;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- // some exception can be normal... other not so!
- try {
- Encrypt (encryptor, input, output);
- }
- catch (Exception e) {
- if (e.Message != "Input buffer contains insufficient data. ")
- Fail ("Rijndael_k128b192_ECB_Zeros: This isn't the expected exception: " + e.ToString ());
- }
- }
- public void TestRijndael_k128b192_ECB_PKCS7 ()
- {
- byte[] key = { 0x78, 0x75, 0x1F, 0xE7, 0xFA, 0x1F, 0xF4, 0x2D, 0x31, 0x36, 0x14, 0xA5, 0xB8, 0x31, 0x97, 0x47 };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0x91, 0x2F, 0xDC, 0x19, 0xC7, 0x6C, 0x67, 0x4A, 0x51, 0xE7, 0x08, 0xA5, 0xF9, 0xC6, 0xC3, 0x56, 0xF2, 0xED, 0xBD, 0xC9, 0x71, 0x9F, 0x02, 0xAF };
- byte[] expected = { 0xB1, 0x0D, 0xFD, 0xB0, 0x89, 0x3C, 0xF5, 0x52, 0x62, 0x22, 0x41, 0x20, 0xE4, 0x34, 0x03, 0x78, 0x37, 0xC2, 0xB1, 0xF9, 0x26, 0x0A, 0x7F, 0x0E, 0xB1, 0x0D, 0xFD, 0xB0, 0x89, 0x3C, 0xF5, 0x52, 0x62, 0x22, 0x41, 0x20, 0xE4, 0x34, 0x03, 0x78, 0x37, 0xC2, 0xB1, 0xF9, 0x26, 0x0A, 0x7F, 0x0E, 0xF9, 0x7A, 0x2D, 0xF9, 0x5C, 0xD5, 0xEA, 0x06, 0x18, 0xC9, 0x06, 0xD4, 0xD0, 0x0B, 0xD6, 0x19, 0x4E, 0x7E, 0x9C, 0x5F, 0xDE, 0x3D, 0xB4, 0x2A };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 192;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("Rijndael_k128b192_ECB_PKCS7 Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("Rijndael_k128b192_ECB_PKCS7 b1==b2", block1, block2);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("Rijndael_k128b192_ECB_PKCS7 Decrypt", input, original);
- }
- public void TestRijndael_k128b192_CBC_None ()
- {
- byte[] key = { 0xBD, 0x01, 0x0F, 0x53, 0x53, 0x14, 0x90, 0x58, 0x22, 0x81, 0x6F, 0x79, 0x8C, 0x68, 0x21, 0x21 };
- byte[] iv = { 0xEE, 0x7B, 0xC0, 0x5F, 0x32, 0x59, 0x56, 0xB6, 0x7C, 0x17, 0x04, 0xC5, 0x64, 0x6A, 0xA1, 0x35, 0x6F, 0xAC, 0xB8, 0xCE, 0xFA, 0xCC, 0x76, 0xBE };
- byte[] expected = { 0x5D, 0xF5, 0x03, 0xD7, 0x17, 0xEE, 0x05, 0x18, 0x63, 0x99, 0xAB, 0x58, 0xBB, 0xC0, 0x04, 0x0A, 0x52, 0x1D, 0x4E, 0xA4, 0x8B, 0x68, 0xA3, 0x63, 0x7A, 0xBD, 0xAF, 0x0C, 0x85, 0x5D, 0xF8, 0x0D, 0x7A, 0x01, 0xF0, 0x76, 0x24, 0xF1, 0x8A, 0x95, 0x8B, 0xB2, 0xC0, 0xF7, 0x1D, 0xC5, 0x0E, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 192;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("Rijndael_k128b192_CBC_None Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("Rijndael_k128b192_CBC_None Decrypt", input, original);
- }
- public void TestRijndael_k128b192_CBC_Zeros ()
- {
- byte[] key = { 0xE2, 0x9C, 0x2A, 0xAA, 0xD0, 0x02, 0xDD, 0xDF, 0xFE, 0xD7, 0xB0, 0x21, 0x1E, 0x52, 0xE5, 0x25 };
- byte[] iv = { 0xED, 0xF5, 0xD7, 0xF7, 0x8D, 0xB6, 0x91, 0x00, 0x81, 0x88, 0x75, 0x8C, 0x61, 0x13, 0x84, 0x46, 0x2A, 0x53, 0x02, 0xE9, 0xBB, 0x01, 0xF8, 0x24 };
- byte[] expected = { 0x55, 0x48, 0x90, 0x63, 0x5B, 0x93, 0x09, 0xA7, 0xF7, 0xB2, 0xC0, 0x4D, 0xB1, 0x1A, 0xF7, 0xC7, 0xF7, 0xC0, 0xB6, 0x29, 0x7A, 0x50, 0x4E, 0x52, 0x2F, 0x68, 0x49, 0x92, 0x80, 0x0D, 0xBD, 0x89, 0x34, 0x84, 0x60, 0x87, 0x2C, 0x50, 0x65, 0xFF, 0xAE, 0x0E, 0x7B, 0x30, 0x3D, 0xFA, 0x93, 0xE6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 192;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- // some exception can be normal... other not so!
- try {
- Encrypt (encryptor, input, output);
- }
- catch (Exception e) {
- if (e.Message != "Input buffer contains insufficient data. ")
- Fail ("Rijndael_k128b192_CBC_Zeros: This isn't the expected exception: " + e.ToString ());
- }
- }
- public void TestRijndael_k128b192_CBC_PKCS7 ()
- {
- byte[] key = { 0x14, 0x6C, 0x36, 0x5E, 0x22, 0xE9, 0x25, 0x1E, 0xC9, 0x1F, 0xA7, 0xC9, 0xA5, 0x19, 0x2C, 0x09 };
- byte[] iv = { 0xE2, 0x6F, 0xA7, 0xDC, 0x36, 0x32, 0xF7, 0x28, 0x8B, 0x09, 0x78, 0xB9, 0x30, 0x6A, 0x3F, 0xD0, 0xA8, 0x5E, 0x1F, 0x7D, 0x8F, 0xDE, 0x5B, 0xA4 };
- byte[] expected = { 0x9D, 0x08, 0xFD, 0xDE, 0x64, 0x97, 0x1D, 0x88, 0xB4, 0xCD, 0x70, 0xDD, 0xCC, 0x95, 0x1C, 0xAE, 0x01, 0x4B, 0x14, 0x19, 0x69, 0x58, 0xCE, 0x14, 0xA6, 0xF6, 0xD0, 0x25, 0xCE, 0xD6, 0xBB, 0xD5, 0x8C, 0xF6, 0xBF, 0x54, 0x66, 0x1D, 0xAE, 0x03, 0x6C, 0x81, 0xBF, 0xC6, 0x06, 0xB3, 0x64, 0x39, 0x73, 0x0A, 0x54, 0xB8, 0x3F, 0x3D, 0x1D, 0xFA, 0xB8, 0xBB, 0x53, 0x34, 0xEC, 0x69, 0xBD, 0xC3, 0xC1, 0xB2, 0x8D, 0x7D, 0x08, 0xE4, 0xFA, 0x82 };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 192;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("Rijndael_k128b192_CBC_PKCS7 Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("Rijndael_k128b192_CBC_PKCS7 Decrypt", input, original);
- }
- /* Invalid parameters Rijndael_k128b192_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters Rijndael_k128b192_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters Rijndael_k128b192_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters Rijndael_k128b192_CFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters Rijndael_k128b192_CFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters Rijndael_k128b192_CFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters Rijndael_k128b192_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters Rijndael_k128b192_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters Rijndael_k128b192_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
- public void TestRijndael_k128b256_ECB_None ()
- {
- byte[] key = { 0xD5, 0xB9, 0x92, 0x27, 0xC0, 0xBB, 0x86, 0x06, 0x19, 0xD9, 0xA4, 0x1B, 0x9E, 0x7A, 0xF0, 0x3D };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0x3C, 0x72, 0xD4, 0xBA, 0xC8, 0xCA, 0xAD, 0x8B, 0x94, 0x00, 0xF3, 0x4E, 0xE9, 0xAC, 0xFB, 0x15, 0xA2, 0x06, 0xFE, 0xA3, 0x33, 0x18, 0x48, 0x55, 0xD5, 0x6B, 0x8F, 0x13, 0xEF, 0xB6, 0x34, 0xF8 };
- byte[] expected = { 0x9A, 0x86, 0x3A, 0xE6, 0x23, 0x50, 0x4D, 0xBD, 0x4B, 0xD3, 0x1A, 0xDE, 0x83, 0x13, 0x4A, 0x82, 0xEF, 0x99, 0x7D, 0x19, 0xB0, 0x01, 0x4E, 0x46, 0x4B, 0xCF, 0x99, 0x66, 0x10, 0x23, 0x6E, 0x6C, 0x9A, 0x86, 0x3A, 0xE6, 0x23, 0x50, 0x4D, 0xBD, 0x4B, 0xD3, 0x1A, 0xDE, 0x83, 0x13, 0x4A, 0x82, 0xEF, 0x99, 0x7D, 0x19, 0xB0, 0x01, 0x4E, 0x46, 0x4B, 0xCF, 0x99, 0x66, 0x10, 0x23, 0x6E, 0x6C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 256;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("Rijndael_k128b256_ECB_None Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("Rijndael_k128b256_ECB_None b1==b2", block1, block2);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("Rijndael_k128b256_ECB_None Decrypt", input, original);
- }
- public void TestRijndael_k128b256_ECB_Zeros ()
- {
- byte[] key = { 0x3C, 0xA6, 0xD7, 0xDA, 0xE3, 0x4D, 0x32, 0x67, 0xA8, 0xF5, 0xFF, 0xFF, 0xEE, 0xE8, 0xD4, 0xB2 };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0xC8, 0x0A, 0x40, 0x30, 0x7C, 0x7E, 0x75, 0xDE, 0x71, 0x64, 0x59, 0xCE, 0x03, 0x40, 0x8F, 0x50, 0xC7, 0x5E, 0xA2, 0x27, 0x5F, 0x12, 0x57, 0xF4, 0xB7, 0xAD, 0x95, 0xAD, 0x95, 0x84, 0xBE, 0x3C };
- byte[] expected = { 0x6D, 0x57, 0xCA, 0xED, 0x29, 0xBA, 0xA6, 0x3A, 0x3D, 0x02, 0xE1, 0x21, 0x39, 0xB0, 0x34, 0x41, 0xFC, 0xAC, 0x55, 0x8C, 0x61, 0xAE, 0x18, 0x7D, 0x7A, 0x41, 0x81, 0x1C, 0x53, 0x5F, 0x3D, 0xB1, 0x6D, 0x57, 0xCA, 0xED, 0x29, 0xBA, 0xA6, 0x3A, 0x3D, 0x02, 0xE1, 0x21, 0x39, 0xB0, 0x34, 0x41, 0xFC, 0xAC, 0x55, 0x8C, 0x61, 0xAE, 0x18, 0x7D, 0x7A, 0x41, 0x81, 0x1C, 0x53, 0x5F, 0x3D, 0xB1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 256;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- // some exception can be normal... other not so!
- try {
- Encrypt (encryptor, input, output);
- }
- catch (Exception e) {
- if (e.Message != "Input buffer contains insufficient data. ")
- Fail ("Rijndael_k128b256_ECB_Zeros: This isn't the expected exception: " + e.ToString ());
- }
- }
- public void TestRijndael_k128b256_ECB_PKCS7 ()
- {
- byte[] key = { 0xED, 0xBA, 0x84, 0x92, 0x50, 0x93, 0x9B, 0xE4, 0xC4, 0x83, 0x31, 0x8E, 0x11, 0x86, 0xAE, 0xC9 };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0x43, 0x98, 0x73, 0xFE, 0x77, 0x4D, 0x75, 0x79, 0xC7, 0xEF, 0x5C, 0x89, 0xFA, 0x5E, 0x07, 0x85, 0x0B, 0x21, 0x59, 0x8B, 0x8A, 0x1D, 0x11, 0x07, 0xA0, 0xC4, 0x3E, 0x11, 0x7F, 0x5D, 0xFE, 0xEE };
- byte[] expected = { 0xA0, 0x56, 0xD6, 0x6B, 0x48, 0x77, 0xCC, 0x51, 0x0F, 0x04, 0x58, 0x16, 0x46, 0x04, 0x36, 0x66, 0xBB, 0x4D, 0x88, 0x71, 0xFF, 0x65, 0x0B, 0xFD, 0x52, 0x8D, 0xE8, 0xAF, 0x97, 0x78, 0xBD, 0x82, 0xA0, 0x56, 0xD6, 0x6B, 0x48, 0x77, 0xCC, 0x51, 0x0F, 0x04, 0x58, 0x16, 0x46, 0x04, 0x36, 0x66, 0xBB, 0x4D, 0x88, 0x71, 0xFF, 0x65, 0x0B, 0xFD, 0x52, 0x8D, 0xE8, 0xAF, 0x97, 0x78, 0xBD, 0x82, 0x66, 0x2C, 0x2B, 0x59, 0xC8, 0x47, 0x3E, 0xE0, 0xC4, 0xA5, 0x22, 0x79, 0x6C, 0xCF, 0x18, 0x10, 0xDA, 0xB5, 0xE9, 0xB1, 0x21, 0xCA, 0xCC, 0xD6, 0xF7, 0xDC, 0xA5, 0xD4, 0x29, 0x10, 0x8A, 0xA4 };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 256;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("Rijndael_k128b256_ECB_PKCS7 Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("Rijndael_k128b256_ECB_PKCS7 b1==b2", block1, block2);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("Rijndael_k128b256_ECB_PKCS7 Decrypt", input, original);
- }
- public void TestRijndael_k128b256_CBC_None ()
- {
- byte[] key = { 0x23, 0x09, 0x30, 0xC7, 0x01, 0x81, 0x1D, 0x2E, 0xD6, 0x6A, 0xC9, 0x99, 0x0D, 0x3D, 0x99, 0x79 };
- byte[] iv = { 0x24, 0x2B, 0xCF, 0xFF, 0x81, 0x8C, 0xBE, 0x55, 0x1D, 0x8A, 0xDA, 0xF8, 0x81, 0xA7, 0x5A, 0xD1, 0xA6, 0x88, 0xC6, 0x90, 0xC4, 0x33, 0xCD, 0x37, 0x11, 0xCC, 0x64, 0x42, 0xD8, 0x2C, 0xA6, 0xE0 };
- byte[] expected = { 0xEF, 0xA5, 0xAB, 0xDB, 0x71, 0xE3, 0x9A, 0x33, 0x45, 0x74, 0xB7, 0x90, 0xED, 0xD8, 0xDE, 0x33, 0x56, 0xEA, 0x75, 0xE0, 0x42, 0x51, 0xAD, 0xEE, 0x9C, 0x74, 0xC8, 0x6B, 0x99, 0x88, 0xD2, 0x13, 0xB2, 0x80, 0x5E, 0xB3, 0xDC, 0xE3, 0x49, 0x43, 0x86, 0x10, 0xC7, 0xCC, 0xE2, 0xE8, 0xCD, 0x79, 0x5C, 0x69, 0x19, 0xD0, 0xE2, 0x70, 0xB1, 0x25, 0x21, 0xB5, 0xC0, 0x69, 0xAB, 0x3D, 0x25, 0x9A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 256;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("Rijndael_k128b256_CBC_None Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("Rijndael_k128b256_CBC_None Decrypt", input, original);
- }
- public void TestRijndael_k128b256_CBC_Zeros ()
- {
- byte[] key = { 0xB6, 0xE5, 0xA0, 0x6F, 0x35, 0xA9, 0x25, 0x31, 0x5B, 0x8C, 0x52, 0x87, 0x26, 0x80, 0xB1, 0x42 };
- byte[] iv = { 0xFD, 0x8E, 0xD8, 0x17, 0xEB, 0x9F, 0xC6, 0x5B, 0xD7, 0x42, 0xF4, 0x79, 0x68, 0x38, 0xEE, 0xC6, 0x15, 0x83, 0xFF, 0x18, 0xA5, 0x24, 0x80, 0x65, 0xCE, 0xF3, 0xED, 0xA8, 0x0E, 0x60, 0xB4, 0xA0 };
- byte[] expected = { 0xC6, 0x0C, 0xE3, 0x6A, 0x8A, 0x98, 0xC2, 0xF7, 0x77, 0x59, 0x2C, 0x77, 0x88, 0x3F, 0xCE, 0x12, 0xFB, 0xFB, 0xB0, 0x20, 0xE5, 0xBC, 0xDB, 0x30, 0xE8, 0x1C, 0x19, 0xEA, 0x4C, 0x3A, 0x2E, 0xAF, 0x57, 0x4B, 0x05, 0xE8, 0xD4, 0xC9, 0xB2, 0xC4, 0x00, 0x35, 0xE0, 0x57, 0x7D, 0xAF, 0x11, 0xB4, 0xB2, 0x84, 0xCD, 0x7F, 0x6C, 0x6E, 0xD0, 0xDA, 0x58, 0x90, 0xF6, 0x9A, 0x51, 0x2C, 0x74, 0x0D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 256;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- // some exception can be normal... other not so!
- try {
- Encrypt (encryptor, input, output);
- }
- catch (Exception e) {
- if (e.Message != "Input buffer contains insufficient data. ")
- Fail ("Rijndael_k128b256_CBC_Zeros: This isn't the expected exception: " + e.ToString ());
- }
- }
- public void TestRijndael_k128b256_CBC_PKCS7 ()
- {
- byte[] key = { 0xAE, 0x7A, 0xD9, 0x55, 0xBF, 0x55, 0xB2, 0x40, 0x4A, 0x48, 0x5F, 0x06, 0xAA, 0x04, 0x45, 0x0A };
- byte[] iv = { 0xB9, 0xD7, 0xC5, 0x09, 0x93, 0xED, 0x68, 0xC4, 0x5A, 0x82, 0x8F, 0xBD, 0x2F, 0xB4, 0x3B, 0x84, 0xBA, 0xE4, 0x46, 0x51, 0xAD, 0xAB, 0xA5, 0xCC, 0xB7, 0x59, 0x31, 0x9E, 0xBB, 0xFA, 0x54, 0x10 };
- byte[] expected = { 0xAC, 0xD7, 0x42, 0x01, 0x60, 0x36, 0xD3, 0xE1, 0xAE, 0x60, 0xC1, 0x5E, 0xAD, 0x4E, 0x81, 0xE1, 0x65, 0xFB, 0xF0, 0x06, 0x89, 0xC5, 0xAD, 0x71, 0x62, 0x81, 0x41, 0xC7, 0xC7, 0xC2, 0xAA, 0x1E, 0x76, 0x88, 0x41, 0x23, 0xFB, 0xFF, 0x44, 0x01, 0xA4, 0xB9, 0x61, 0xC0, 0x1B, 0x54, 0x09, 0x45, 0x1C, 0x17, 0xE3, 0x0A, 0x4A, 0x0A, 0xC5, 0x6F, 0x77, 0xB0, 0xDB, 0xE1, 0xD4, 0xCD, 0x28, 0xD6, 0xA6, 0x40, 0x8F, 0x2B, 0x49, 0x2C, 0xDF, 0x4D, 0x6D, 0x78, 0x24, 0x65, 0x37, 0x61, 0x05, 0xCD, 0xBC, 0x15, 0x37, 0x67, 0x65, 0xEF, 0xCB, 0x8A, 0xEE, 0x53, 0x9D, 0x29, 0x62, 0x73, 0x51, 0xD2 };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 256;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("Rijndael_k128b256_CBC_PKCS7 Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("Rijndael_k128b256_CBC_PKCS7 Decrypt", input, original);
- }
- /* Invalid parameters Rijndael_k128b256_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters Rijndael_k128b256_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters Rijndael_k128b256_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters Rijndael_k128b256_CFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters Rijndael_k128b256_CFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters Rijndael_k128b256_CFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters Rijndael_k128b256_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters Rijndael_k128b256_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters Rijndael_k128b256_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
- public void TestRijndael_k192b128_ECB_None ()
- {
- byte[] key = { 0xA4, 0x51, 0x15, 0x32, 0xE7, 0xFC, 0x6F, 0x22, 0x73, 0x72, 0xB0, 0xAD, 0x67, 0x4C, 0x84, 0xB4, 0xB2, 0xAF, 0x50, 0x74, 0x5A, 0x4D, 0xB7, 0x2A };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0x83, 0x22, 0x1B, 0x6C, 0x66, 0x1F, 0x4A, 0xB7, 0x55, 0xAF, 0x5B, 0xBF, 0x4A, 0x05, 0x73, 0x24 };
- byte[] expected = { 0x6A, 0x1D, 0xA5, 0xBE, 0x7F, 0x6C, 0x0A, 0x98, 0x2A, 0x09, 0x4B, 0x70, 0xC1, 0xA1, 0xBC, 0x75, 0x6A, 0x1D, 0xA5, 0xBE, 0x7F, 0x6C, 0x0A, 0x98, 0x2A, 0x09, 0x4B, 0x70, 0xC1, 0xA1, 0xBC, 0x75, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 128;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("Rijndael_k192b128_ECB_None Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("Rijndael_k192b128_ECB_None b1==b2", block1, block2);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("Rijndael_k192b128_ECB_None Decrypt", input, original);
- }
- public void TestRijndael_k192b128_ECB_Zeros ()
- {
- byte[] key = { 0xB4, 0x65, 0x79, 0x30, 0x92, 0x6A, 0xEC, 0x78, 0xBA, 0x9B, 0x8B, 0x36, 0x7C, 0x8F, 0x6B, 0x8A, 0x79, 0x7F, 0x8A, 0xDA, 0xB4, 0x06, 0x23, 0x4C };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0x43, 0xBA, 0x1C, 0xFB, 0x33, 0xB4, 0x3B, 0x38, 0x5C, 0x21, 0x13, 0xDD, 0x9A, 0x3A, 0xF1, 0xEE };
- byte[] expected = { 0xB1, 0x45, 0x70, 0xFC, 0xB5, 0x82, 0x49, 0x9F, 0xEA, 0x50, 0x0C, 0xEA, 0xFD, 0x13, 0xA8, 0xE8, 0xB1, 0x45, 0x70, 0xFC, 0xB5, 0x82, 0x49, 0x9F, 0xEA, 0x50, 0x0C, 0xEA, 0xFD, 0x13, 0xA8, 0xE8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 128;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- // some exception can be normal... other not so!
- try {
- Encrypt (encryptor, input, output);
- }
- catch (Exception e) {
- if (e.Message != "Input buffer contains insufficient data. ")
- Fail ("Rijndael_k192b128_ECB_Zeros: This isn't the expected exception: " + e.ToString ());
- }
- }
- public void TestRijndael_k192b128_ECB_PKCS7 ()
- {
- byte[] key = { 0x06, 0xC3, 0x07, 0x6A, 0x36, 0xE5, 0xF3, 0xCF, 0x33, 0x87, 0x22, 0x03, 0x5A, 0xFA, 0x4F, 0x25, 0x9D, 0xE4, 0x81, 0xA4, 0x9E, 0xB4, 0x5D, 0x84 };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0xB0, 0xF9, 0x9F, 0x2D, 0x8D, 0xD0, 0x2D, 0xA1, 0x51, 0xDB, 0x07, 0xA3, 0x34, 0x28, 0x4F, 0x25 };
- byte[] expected = { 0xE9, 0xB9, 0xE5, 0x89, 0x0E, 0xF7, 0x3C, 0xCF, 0x63, 0x6B, 0xCD, 0x33, 0x85, 0x81, 0x02, 0x75, 0xE9, 0xB9, 0xE5, 0x89, 0x0E, 0xF7, 0x3C, 0xCF, 0x63, 0x6B, 0xCD, 0x33, 0x85, 0x81, 0x02, 0x75, 0xE8, 0x31, 0x03, 0x87, 0xFF, 0x9D, 0x7A, 0xAB, 0x81, 0x82, 0x63, 0x6B, 0xAA, 0x6F, 0x20, 0x21 };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 128;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("Rijndael_k192b128_ECB_PKCS7 Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("Rijndael_k192b128_ECB_PKCS7 b1==b2", block1, block2);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("Rijndael_k192b128_ECB_PKCS7 Decrypt", input, original);
- }
- public void TestRijndael_k192b128_CBC_None ()
- {
- byte[] key = { 0x8F, 0x85, 0x39, 0xC2, 0xAC, 0x25, 0xBD, 0x54, 0xDE, 0x89, 0x2A, 0x67, 0x2C, 0xF0, 0xE5, 0x7E, 0xAA, 0x7E, 0xC4, 0xFB, 0xCD, 0x31, 0xD9, 0xFA };
- byte[] iv = { 0xCA, 0xC4, 0x8D, 0x38, 0x28, 0x29, 0xC2, 0xBF, 0xD8, 0x7A, 0xCA, 0x56, 0xBF, 0x59, 0x6B, 0xCE };
- byte[] expected = { 0x22, 0x66, 0xB0, 0x6C, 0xC1, 0x18, 0xBB, 0x43, 0x6B, 0xB9, 0x42, 0x16, 0x4D, 0xFB, 0x96, 0x7C, 0xEC, 0xCA, 0xB8, 0x09, 0x02, 0x8C, 0x2E, 0x4D, 0x4D, 0x90, 0x03, 0xEA, 0x0F, 0x69, 0x20, 0xA2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 128;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("Rijndael_k192b128_CBC_None Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("Rijndael_k192b128_CBC_None Decrypt", input, original);
- }
- public void TestRijndael_k192b128_CBC_Zeros ()
- {
- byte[] key = { 0xA7, 0x3E, 0xEE, 0x4B, 0xF5, 0x0E, 0x05, 0x03, 0xE2, 0x50, 0xF1, 0xBC, 0xEB, 0x57, 0x60, 0x79, 0x83, 0x5D, 0xFC, 0x42, 0x65, 0x41, 0xCF, 0x48 };
- byte[] iv = { 0xC9, 0x76, 0xCE, 0x21, 0xDF, 0x46, 0xB0, 0x23, 0x19, 0xB6, 0xD5, 0x80, 0x1F, 0xBA, 0x15, 0xDB };
- byte[] expected = { 0x63, 0xED, 0x15, 0xBE, 0xB9, 0x4E, 0x9E, 0x30, 0xB1, 0xC5, 0x31, 0xCB, 0x02, 0x88, 0xB4, 0x8F, 0xF5, 0xB0, 0x53, 0x8D, 0xD1, 0x35, 0xB7, 0x85, 0xED, 0x02, 0x79, 0x03, 0xC1, 0x13, 0xCE, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 128;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- // some exception can be normal... other not so!
- try {
- Encrypt (encryptor, input, output);
- }
- catch (Exception e) {
- if (e.Message != "Input buffer contains insufficient data. ")
- Fail ("Rijndael_k192b128_CBC_Zeros: This isn't the expected exception: " + e.ToString ());
- }
- }
- public void TestRijndael_k192b128_CBC_PKCS7 ()
- {
- byte[] key = { 0x0F, 0x00, 0x54, 0xCD, 0x2A, 0x66, 0x21, 0xF0, 0x74, 0x64, 0x65, 0xC6, 0xE1, 0xC6, 0xCD, 0x11, 0x05, 0x04, 0xA7, 0x23, 0x48, 0x4E, 0xB3, 0x84 };
- byte[] iv = { 0xDA, 0xE6, 0x7F, 0x27, 0x8A, 0xE6, 0x8E, 0x13, 0x9D, 0x15, 0x0D, 0x80, 0x4B, 0xC4, 0x9F, 0x08 };
- byte[] expected = { 0x0D, 0x7E, 0x32, 0xE0, 0xFA, 0x25, 0xB1, 0x52, 0x37, 0x27, 0xF3, 0x99, 0xA7, 0x08, 0x7F, 0x8E, 0xAA, 0x98, 0x36, 0x42, 0x21, 0xCF, 0x3B, 0xF1, 0x95, 0x99, 0xF4, 0x00, 0x36, 0x47, 0x0F, 0x25, 0x43, 0x36, 0x43, 0x68, 0x40, 0xB1, 0x1A, 0xFA, 0xDC, 0x43, 0x94, 0xD7, 0x16, 0x28, 0xFD, 0xDD };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 128;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("Rijndael_k192b128_CBC_PKCS7 Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("Rijndael_k192b128_CBC_PKCS7 Decrypt", input, original);
- }
- /* Invalid parameters Rijndael_k192b128_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters Rijndael_k192b128_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters Rijndael_k192b128_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters Rijndael_k192b128_CFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters Rijndael_k192b128_CFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters Rijndael_k192b128_CFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters Rijndael_k192b128_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters Rijndael_k192b128_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters Rijndael_k192b128_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
- public void TestRijndael_k192b192_ECB_None ()
- {
- byte[] key = { 0x33, 0x09, 0x20, 0xF4, 0x69, 0x76, 0x98, 0x57, 0x93, 0x1A, 0x37, 0x31, 0xFA, 0x2D, 0x49, 0xEA, 0xE4, 0xD4, 0x6C, 0xA5, 0x91, 0x2A, 0xD8, 0x54 };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0x7F, 0x2E, 0xE0, 0x80, 0x52, 0x2F, 0x63, 0x3F, 0x8F, 0x09, 0x85, 0x3D, 0x21, 0x73, 0x40, 0x45, 0xB0, 0x85, 0xDE, 0xB9, 0xC0, 0xA1, 0x06, 0xB2 };
- byte[] expected = { 0x93, 0x0B, 0xF0, 0xA0, 0x0C, 0x79, 0x99, 0x40, 0x17, 0x62, 0xD6, 0xD8, 0x1C, 0x3B, 0xB3, 0x18, 0x57, 0xA6, 0x01, 0x68, 0xEA, 0x73, 0x9A, 0x0A, 0x93, 0x0B, 0xF0, 0xA0, 0x0C, 0x79, 0x99, 0x40, 0x17, 0x62, 0xD6, 0xD8, 0x1C, 0x3B, 0xB3, 0x18, 0x57, 0xA6, 0x01, 0x68, 0xEA, 0x73, 0x9A, 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 192;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("Rijndael_k192b192_ECB_None Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("Rijndael_k192b192_ECB_None b1==b2", block1, block2);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("Rijndael_k192b192_ECB_None Decrypt", input, original);
- }
- public void TestRijndael_k192b192_ECB_Zeros ()
- {
- byte[] key = { 0xB5, 0x06, 0x72, 0x5F, 0x4E, 0x37, 0x62, 0x8F, 0x68, 0xE5, 0x0A, 0x80, 0xC6, 0x39, 0xB9, 0x13, 0xC7, 0xD8, 0x74, 0x1F, 0xE8, 0xD1, 0x99, 0x9E };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0x11, 0x49, 0xA6, 0x58, 0x8F, 0xF1, 0x8E, 0xB3, 0x19, 0x81, 0xFE, 0xB8, 0x09, 0x69, 0x3D, 0x01, 0x21, 0x08, 0xCD, 0x1D, 0xEB, 0x98, 0xA7, 0xF1 };
- byte[] expected = { 0x42, 0xD5, 0xF0, 0x37, 0xFF, 0xBB, 0x81, 0xC1, 0x6F, 0x12, 0xCF, 0x65, 0x29, 0xC5, 0x88, 0xBE, 0x08, 0x88, 0xBF, 0x6F, 0xDF, 0x23, 0x82, 0x5E, 0x42, 0xD5, 0xF0, 0x37, 0xFF, 0xBB, 0x81, 0xC1, 0x6F, 0x12, 0xCF, 0x65, 0x29, 0xC5, 0x88, 0xBE, 0x08, 0x88, 0xBF, 0x6F, 0xDF, 0x23, 0x82, 0x5E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 192;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- // some exception can be normal... other not so!
- try {
- Encrypt (encryptor, input, output);
- }
- catch (Exception e) {
- if (e.Message != "Input buffer contains insufficient data. ")
- Fail ("Rijndael_k192b192_ECB_Zeros: This isn't the expected exception: " + e.ToString ());
- }
- }
- public void TestRijndael_k192b192_ECB_PKCS7 ()
- {
- byte[] key = { 0x40, 0xE3, 0xF1, 0x90, 0xC2, 0xA9, 0x59, 0xB8, 0x01, 0x72, 0x01, 0x1F, 0x10, 0x11, 0x0E, 0x8F, 0xA1, 0xF2, 0x62, 0xD7, 0x0A, 0x65, 0xCD, 0xC4 };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0x06, 0x08, 0x07, 0xB3, 0x8F, 0x84, 0xD9, 0xB3, 0xF9, 0x11, 0xFC, 0x0B, 0x9C, 0xC4, 0x6E, 0x41, 0xE1, 0xCC, 0x6F, 0x26, 0x6D, 0x70, 0xC6, 0x47 };
- byte[] expected = { 0xCD, 0x70, 0x93, 0x83, 0x82, 0xB1, 0xA3, 0x74, 0x8A, 0xBD, 0x0C, 0x0D, 0x8B, 0x9F, 0x3C, 0xDF, 0xBC, 0x8E, 0x64, 0x6E, 0xF7, 0xF5, 0x10, 0x0E, 0xCD, 0x70, 0x93, 0x83, 0x82, 0xB1, 0xA3, 0x74, 0x8A, 0xBD, 0x0C, 0x0D, 0x8B, 0x9F, 0x3C, 0xDF, 0xBC, 0x8E, 0x64, 0x6E, 0xF7, 0xF5, 0x10, 0x0E, 0x2D, 0xB2, 0xBD, 0xA1, 0x21, 0x56, 0xD1, 0x33, 0x00, 0x1C, 0x71, 0xAF, 0x9A, 0x48, 0x24, 0x00, 0xED, 0xA1, 0xE4, 0x2B, 0xF4, 0xF3, 0xD2, 0x5F };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 192;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("Rijndael_k192b192_ECB_PKCS7 Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("Rijndael_k192b192_ECB_PKCS7 b1==b2", block1, block2);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("Rijndael_k192b192_ECB_PKCS7 Decrypt", input, original);
- }
- public void TestRijndael_k192b192_CBC_None ()
- {
- byte[] key = { 0x21, 0x15, 0x8D, 0x66, 0x7D, 0x81, 0xD6, 0xBD, 0xFF, 0x6D, 0x3F, 0x44, 0x43, 0x0E, 0xD7, 0x07, 0xC9, 0x5F, 0xFF, 0x0A, 0x88, 0x2D, 0xC1, 0xC4 };
- byte[] iv = { 0x43, 0x68, 0xF9, 0x7E, 0xD4, 0x6D, 0xB9, 0xA7, 0x9D, 0xFF, 0x68, 0x7F, 0x4F, 0xBB, 0x14, 0x4D, 0x29, 0x4F, 0x94, 0x8A, 0x83, 0x02, 0x77, 0x1E };
- byte[] expected = { 0x13, 0xD5, 0x9A, 0x4A, 0x96, 0x7E, 0x4F, 0x67, 0x12, 0x31, 0x9B, 0xF5, 0xC5, 0x5A, 0x81, 0xC2, 0x43, 0x51, 0x57, 0x6D, 0xA2, 0xFC, 0x5F, 0x00, 0x49, 0x5A, 0x4E, 0x82, 0x3C, 0xE0, 0x7A, 0x89, 0x2F, 0x36, 0xB3, 0x84, 0x6E, 0x9B, 0x9A, 0xAA, 0x48, 0x1B, 0x0D, 0xA1, 0x42, 0xAD, 0x6F, 0x75, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 192;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("Rijndael_k192b192_CBC_None Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("Rijndael_k192b192_CBC_None Decrypt", input, original);
- }
- public void TestRijndael_k192b192_CBC_Zeros ()
- {
- byte[] key = { 0x81, 0x6F, 0xD7, 0x01, 0xCF, 0x7E, 0x73, 0x8E, 0x18, 0xB7, 0x91, 0x85, 0x70, 0x3B, 0x87, 0xCE, 0xA7, 0xB5, 0xB9, 0xFA, 0x30, 0x3D, 0x26, 0x28 };
- byte[] iv = { 0x5B, 0x34, 0x00, 0xA3, 0x3F, 0xEA, 0x2C, 0xAF, 0x87, 0xA3, 0xB9, 0x15, 0xF8, 0x61, 0x4A, 0x5C, 0x23, 0x2A, 0xF3, 0xA6, 0x7B, 0xFB, 0xEA, 0x1E };
- byte[] expected = { 0xF4, 0x87, 0x7B, 0xC8, 0x41, 0x2C, 0x8E, 0x2C, 0x58, 0x50, 0x6E, 0xE5, 0x79, 0xD1, 0xE8, 0x54, 0xE2, 0x13, 0x55, 0x91, 0x60, 0xF0, 0x35, 0x2D, 0xDB, 0x3A, 0x69, 0x92, 0x3B, 0xD1, 0x6D, 0x89, 0x57, 0x17, 0x2F, 0x31, 0xA1, 0xD9, 0xB1, 0x00, 0x41, 0x54, 0x0C, 0xFC, 0xA4, 0xE0, 0x7F, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 192;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- // some exception can be normal... other not so!
- try {
- Encrypt (encryptor, input, output);
- }
- catch (Exception e) {
- if (e.Message != "Input buffer contains insufficient data. ")
- Fail ("Rijndael_k192b192_CBC_Zeros: This isn't the expected exception: " + e.ToString ());
- }
- }
- public void TestRijndael_k192b192_CBC_PKCS7 ()
- {
- byte[] key = { 0xF4, 0x68, 0x87, 0x59, 0x32, 0x8D, 0x10, 0xA8, 0xC1, 0x32, 0xD0, 0xEC, 0xE5, 0x4A, 0x8A, 0x11, 0x3E, 0x8E, 0x11, 0x48, 0x88, 0xE9, 0xC1, 0x1A };
- byte[] iv = { 0x72, 0xD8, 0x59, 0x64, 0xD0, 0x23, 0x1E, 0x6F, 0xF9, 0x16, 0x98, 0x61, 0x09, 0xE1, 0x33, 0xE2, 0x62, 0xB7, 0x9D, 0xD2, 0xCD, 0x5B, 0x47, 0xD8 };
- byte[] expected = { 0x0B, 0x3C, 0xDD, 0x1F, 0xCA, 0x36, 0x1C, 0x44, 0x0D, 0xC6, 0xC9, 0xF8, 0xE9, 0x96, 0x33, 0x52, 0x89, 0x66, 0x73, 0x9C, 0x43, 0x27, 0x76, 0xE4, 0x84, 0x4F, 0xEF, 0x68, 0x04, 0x83, 0x68, 0x1A, 0x08, 0xA5, 0x6C, 0x22, 0x83, 0x64, 0xD5, 0x9E, 0x58, 0x00, 0x5F, 0xEB, 0x6A, 0xEF, 0x36, 0xDD, 0xD4, 0xF4, 0x21, 0x9F, 0xAB, 0x87, 0xB3, 0xD0, 0x29, 0x04, 0x19, 0x14, 0xD1, 0xD1, 0x66, 0x37, 0x54, 0xBC, 0x40, 0x43, 0xF6, 0xF1, 0x8A, 0x67 };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 192;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("Rijndael_k192b192_CBC_PKCS7 Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("Rijndael_k192b192_CBC_PKCS7 Decrypt", input, original);
- }
- /* Invalid parameters Rijndael_k192b192_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters Rijndael_k192b192_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters Rijndael_k192b192_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters Rijndael_k192b192_CFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters Rijndael_k192b192_CFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters Rijndael_k192b192_CFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters Rijndael_k192b192_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters Rijndael_k192b192_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters Rijndael_k192b192_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
- public void TestRijndael_k192b256_ECB_None ()
- {
- byte[] key = { 0x07, 0xD5, 0xDE, 0x67, 0xAA, 0x99, 0x89, 0x35, 0x41, 0xAA, 0x04, 0x7B, 0xBB, 0x25, 0x91, 0x88, 0xDA, 0xA9, 0x5F, 0xD6, 0x05, 0xA4, 0xF4, 0x7B };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0x21, 0x43, 0xAF, 0xF7, 0x20, 0x60, 0x95, 0x40, 0x42, 0x57, 0x2E, 0x1D, 0xAC, 0x95, 0x39, 0x71, 0x88, 0xDA, 0xC2, 0x22, 0xF4, 0xEA, 0xC8, 0x6F, 0x3B, 0x73, 0xBC, 0xA5, 0xC9, 0x56, 0x2B, 0x38 };
- byte[] expected = { 0xDA, 0xB8, 0xB7, 0xA7, 0x7D, 0x50, 0x08, 0x6A, 0x57, 0x3C, 0x1E, 0xA4, 0xED, 0xDD, 0x3F, 0x93, 0x99, 0x7E, 0xFC, 0x06, 0x3A, 0x9E, 0xAC, 0x82, 0x16, 0xCA, 0xE5, 0x79, 0x2C, 0xA1, 0xAC, 0x5D, 0xDA, 0xB8, 0xB7, 0xA7, 0x7D, 0x50, 0x08, 0x6A, 0x57, 0x3C, 0x1E, 0xA4, 0xED, 0xDD, 0x3F, 0x93, 0x99, 0x7E, 0xFC, 0x06, 0x3A, 0x9E, 0xAC, 0x82, 0x16, 0xCA, 0xE5, 0x79, 0x2C, 0xA1, 0xAC, 0x5D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 256;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("Rijndael_k192b256_ECB_None Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("Rijndael_k192b256_ECB_None b1==b2", block1, block2);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("Rijndael_k192b256_ECB_None Decrypt", input, original);
- }
- public void TestRijndael_k192b256_ECB_Zeros ()
- {
- byte[] key = { 0xE4, 0x87, 0x99, 0x8B, 0xD1, 0x33, 0x03, 0x25, 0x1A, 0xE4, 0x10, 0x6F, 0xC7, 0x7F, 0xC2, 0xDA, 0xAC, 0x99, 0x02, 0xFF, 0x34, 0xEF, 0x10, 0xC0 };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0x67, 0xA7, 0x6E, 0xF5, 0xD8, 0xE2, 0xC3, 0xCB, 0x03, 0xF4, 0x6A, 0x01, 0x71, 0x8E, 0x02, 0xC7, 0x71, 0x73, 0xCF, 0x22, 0x76, 0x15, 0x87, 0x4F, 0x0D, 0x07, 0x43, 0xA6, 0x26, 0xAD, 0x15, 0xDA };
- byte[] expected = { 0xAB, 0x82, 0x14, 0x0D, 0x94, 0x36, 0x61, 0x9D, 0xF9, 0x39, 0xDA, 0x44, 0x34, 0xBA, 0x0D, 0xF5, 0xE6, 0xD2, 0x68, 0x53, 0x60, 0xC6, 0x98, 0x39, 0x4C, 0x90, 0xBE, 0xF6, 0x6E, 0xD8, 0xCB, 0xAA, 0xAB, 0x82, 0x14, 0x0D, 0x94, 0x36, 0x61, 0x9D, 0xF9, 0x39, 0xDA, 0x44, 0x34, 0xBA, 0x0D, 0xF5, 0xE6, 0xD2, 0x68, 0x53, 0x60, 0xC6, 0x98, 0x39, 0x4C, 0x90, 0xBE, 0xF6, 0x6E, 0xD8, 0xCB, 0xAA, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 256;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- // some exception can be normal... other not so!
- try {
- Encrypt (encryptor, input, output);
- }
- catch (Exception e) {
- if (e.Message != "Input buffer contains insufficient data. ")
- Fail ("Rijndael_k192b256_ECB_Zeros: This isn't the expected exception: " + e.ToString ());
- }
- }
- public void TestRijndael_k192b256_ECB_PKCS7 ()
- {
- byte[] key = { 0x15, 0x40, 0x0B, 0xA3, 0xFC, 0x69, 0xF7, 0x2B, 0x55, 0x6F, 0xE9, 0x2C, 0xDA, 0xF8, 0x49, 0xAA, 0x41, 0xB3, 0x3B, 0x61, 0xCA, 0x88, 0x58, 0x19 };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0xCB, 0x37, 0xA1, 0x13, 0x44, 0x0D, 0x72, 0xC0, 0x8B, 0x0E, 0x62, 0xDB, 0xAF, 0x8D, 0x00, 0xC1, 0xF6, 0xF7, 0x2B, 0x60, 0x58, 0x09, 0x46, 0x95, 0x28, 0x9C, 0x87, 0x30, 0xE9, 0xA2, 0x95, 0x80 };
- byte[] expected = { 0xBE, 0x93, 0xB9, 0xEF, 0xC7, 0x57, 0x71, 0xD9, 0xFA, 0x17, 0x6F, 0x9D, 0xBE, 0x2A, 0xF2, 0xE8, 0x17, 0x39, 0x61, 0x6A, 0xEE, 0x51, 0x6D, 0x65, 0xEE, 0x27, 0x50, 0x82, 0xFB, 0x91, 0xFC, 0xDB, 0xBE, 0x93, 0xB9, 0xEF, 0xC7, 0x57, 0x71, 0xD9, 0xFA, 0x17, 0x6F, 0x9D, 0xBE, 0x2A, 0xF2, 0xE8, 0x17, 0x39, 0x61, 0x6A, 0xEE, 0x51, 0x6D, 0x65, 0xEE, 0x27, 0x50, 0x82, 0xFB, 0x91, 0xFC, 0xDB, 0x72, 0x86, 0xCA, 0xC3, 0x5C, 0x0F, 0x55, 0x79, 0x32, 0x96, 0x07, 0x86, 0xD7, 0xF3, 0x23, 0x53, 0xFC, 0x63, 0xBC, 0xD1, 0x76, 0x33, 0x7F, 0x72, 0xF1, 0x0A, 0x60, 0x7F, 0xB2, 0x6A, 0xBA, 0x0B };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 256;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("Rijndael_k192b256_ECB_PKCS7 Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("Rijndael_k192b256_ECB_PKCS7 b1==b2", block1, block2);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("Rijndael_k192b256_ECB_PKCS7 Decrypt", input, original);
- }
- public void TestRijndael_k192b256_CBC_None ()
- {
- byte[] key = { 0x3E, 0xFE, 0x6E, 0xF9, 0x4A, 0xCE, 0x96, 0xB7, 0xDD, 0x34, 0x15, 0x20, 0x85, 0xEA, 0x4B, 0x41, 0xEC, 0xFC, 0xDD, 0x37, 0xD9, 0xF1, 0x9A, 0xE4 };
- byte[] iv = { 0x04, 0x89, 0x29, 0x3F, 0x6A, 0x54, 0xED, 0xF3, 0x8D, 0x1F, 0x62, 0xC8, 0x8C, 0x05, 0x89, 0x62, 0xC2, 0x5E, 0xDB, 0xCA, 0x60, 0xE0, 0x17, 0x03, 0xE5, 0x69, 0x6B, 0x84, 0x44, 0x2C, 0x68, 0xB0 };
- byte[] expected = { 0xA5, 0xCB, 0x68, 0xA8, 0x8A, 0xE0, 0xFD, 0x68, 0xB3, 0x75, 0x51, 0xB8, 0x46, 0x08, 0xEC, 0xE3, 0xDA, 0xE9, 0xBF, 0x49, 0x65, 0x74, 0x84, 0xB7, 0x9A, 0x60, 0x89, 0x43, 0xF2, 0x35, 0xC2, 0xAB, 0x3F, 0xD3, 0x0A, 0x9A, 0x6A, 0x3D, 0xB4, 0x2C, 0xB0, 0x8B, 0x32, 0x28, 0x2B, 0x57, 0x8F, 0x2E, 0xCF, 0x37, 0x24, 0x9B, 0xB5, 0x3B, 0xE6, 0x5E, 0xA7, 0xB9, 0x10, 0x99, 0x36, 0xA7, 0x9C, 0x92, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 256;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("Rijndael_k192b256_CBC_None Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("Rijndael_k192b256_CBC_None Decrypt", input, original);
- }
- public void TestRijndael_k192b256_CBC_Zeros ()
- {
- byte[] key = { 0xB6, 0x93, 0x96, 0xA4, 0xD3, 0xE5, 0x73, 0x81, 0x17, 0x7B, 0x68, 0x92, 0x3A, 0xAF, 0x20, 0x45, 0x75, 0xBA, 0x43, 0x3C, 0x5E, 0x46, 0xF6, 0x15 };
- byte[] iv = { 0x17, 0x23, 0x3C, 0x0C, 0x51, 0xE2, 0x02, 0x8C, 0xC8, 0xD5, 0x5B, 0x00, 0x20, 0xE0, 0x2A, 0xC4, 0x4F, 0xCF, 0x4C, 0x1A, 0xCD, 0x59, 0x6C, 0x2D, 0x50, 0x8E, 0xF9, 0xA0, 0x3F, 0xFD, 0x81, 0xB5 };
- byte[] expected = { 0x93, 0xF0, 0xFC, 0x25, 0x3D, 0x6D, 0x74, 0x1F, 0x88, 0xC9, 0x9F, 0xE6, 0x3A, 0x24, 0x13, 0xE1, 0x7C, 0xEF, 0x79, 0xC6, 0x56, 0x87, 0xCB, 0xD0, 0xB7, 0x15, 0x91, 0x21, 0x7E, 0x17, 0xA2, 0xF1, 0xA6, 0xDA, 0xCA, 0xDF, 0x14, 0x88, 0x5C, 0x35, 0x13, 0x1E, 0xCD, 0x2E, 0xB0, 0xC8, 0x7E, 0x4A, 0xBE, 0xD9, 0x3B, 0x15, 0x8D, 0xC9, 0x2A, 0xC5, 0x2D, 0x7C, 0x24, 0xF3, 0xB4, 0x43, 0xDE, 0xBB, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 256;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- // some exception can be normal... other not so!
- try {
- Encrypt (encryptor, input, output);
- }
- catch (Exception e) {
- if (e.Message != "Input buffer contains insufficient data. ")
- Fail ("Rijndael_k192b256_CBC_Zeros: This isn't the expected exception: " + e.ToString ());
- }
- }
- public void TestRijndael_k192b256_CBC_PKCS7 ()
- {
- byte[] key = { 0x5B, 0x58, 0xA2, 0xF7, 0x12, 0x9B, 0xF1, 0x09, 0x14, 0x98, 0x6F, 0x75, 0x69, 0xF0, 0xB5, 0x02, 0xDE, 0x7E, 0xF3, 0xBF, 0x56, 0x69, 0xEC, 0x5C };
- byte[] iv = { 0x2E, 0x75, 0x1D, 0x3D, 0x2C, 0x01, 0x0B, 0x7A, 0xE6, 0x7C, 0x63, 0xB4, 0x1A, 0xF2, 0x48, 0x62, 0xF2, 0x7A, 0xF0, 0xFA, 0xC9, 0xAD, 0xFF, 0x88, 0x45, 0xE4, 0xFE, 0x5A, 0xA2, 0x87, 0x7A, 0x16 };
- byte[] expected = { 0xD2, 0x9B, 0x71, 0x41, 0xAF, 0xD2, 0x66, 0x52, 0xB1, 0x45, 0xEA, 0x7C, 0xFD, 0xF8, 0xD5, 0x13, 0xAE, 0x3E, 0xCE, 0x84, 0x5B, 0x2A, 0xBB, 0xEA, 0x11, 0xFC, 0x45, 0x98, 0x71, 0xC0, 0x2A, 0x9B, 0xD4, 0x4B, 0xDA, 0xC9, 0xED, 0x8A, 0x86, 0x0B, 0xC4, 0x53, 0x32, 0x46, 0x00, 0x59, 0x12, 0x58, 0x12, 0x8E, 0x95, 0x20, 0xA8, 0xE0, 0x96, 0xEB, 0x62, 0xAF, 0x09, 0x04, 0xE7, 0x00, 0xCE, 0x14, 0x7D, 0x62, 0xE2, 0xE8, 0x85, 0x35, 0x7B, 0x11, 0xCD, 0xA9, 0xA4, 0x48, 0x28, 0x9A, 0xA1, 0x5A, 0x3A, 0x0D, 0x24, 0x00, 0x14, 0xEE, 0x1D, 0x99, 0x46, 0x29, 0x57, 0x56, 0x12, 0x63, 0x08, 0xB1 };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 256;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("Rijndael_k192b256_CBC_PKCS7 Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("Rijndael_k192b256_CBC_PKCS7 Decrypt", input, original);
- }
- /* Invalid parameters Rijndael_k192b256_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters Rijndael_k192b256_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters Rijndael_k192b256_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters Rijndael_k192b256_CFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters Rijndael_k192b256_CFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters Rijndael_k192b256_CFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters Rijndael_k192b256_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters Rijndael_k192b256_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters Rijndael_k192b256_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
- public void TestRijndael_k256b128_ECB_None ()
- {
- byte[] key = { 0x5B, 0xA0, 0xA9, 0x6B, 0x20, 0x14, 0xF4, 0x4E, 0x2E, 0x9A, 0x34, 0x84, 0xD3, 0xB9, 0x62, 0x45, 0xB1, 0x98, 0x35, 0xAE, 0xA7, 0xED, 0x80, 0x67, 0xE2, 0x77, 0xC4, 0xD5, 0x6B, 0xBD, 0x6E, 0xCF };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0xF5, 0xBD, 0x6D, 0xDF, 0x0C, 0x8E, 0xC5, 0x39, 0x25, 0xBE, 0x1A, 0x80, 0xF8, 0x79, 0xEC, 0x93 };
- byte[] expected = { 0x54, 0xF5, 0x87, 0xE7, 0x73, 0xB7, 0x04, 0xBF, 0xBB, 0x16, 0x3D, 0x5A, 0xC0, 0x68, 0x7C, 0x17, 0x54, 0xF5, 0x87, 0xE7, 0x73, 0xB7, 0x04, 0xBF, 0xBB, 0x16, 0x3D, 0x5A, 0xC0, 0x68, 0x7C, 0x17, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 128;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("Rijndael_k256b128_ECB_None Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("Rijndael_k256b128_ECB_None b1==b2", block1, block2);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("Rijndael_k256b128_ECB_None Decrypt", input, original);
- }
- public void TestRijndael_k256b128_ECB_Zeros ()
- {
- byte[] key = { 0x77, 0xE1, 0xB2, 0xF9, 0x14, 0xF0, 0x77, 0xCE, 0xDB, 0x28, 0xD4, 0xA5, 0x0E, 0xA6, 0x73, 0x23, 0xD8, 0x46, 0xB7, 0x1A, 0x16, 0x92, 0xDB, 0x7E, 0x80, 0xDF, 0x5E, 0x9A, 0x16, 0x08, 0xFF, 0x6D };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0x48, 0xEC, 0x4A, 0x12, 0xAC, 0x9C, 0xB5, 0x72, 0xEB, 0x12, 0x14, 0xFB, 0xE1, 0x6D, 0xCF, 0xA3 };
- byte[] expected = { 0x82, 0x6C, 0xC7, 0xA6, 0xC2, 0x57, 0x07, 0xF9, 0x2F, 0x92, 0x95, 0x90, 0x65, 0xFA, 0x1D, 0xFA, 0x82, 0x6C, 0xC7, 0xA6, 0xC2, 0x57, 0x07, 0xF9, 0x2F, 0x92, 0x95, 0x90, 0x65, 0xFA, 0x1D, 0xFA, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 128;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- // some exception can be normal... other not so!
- try {
- Encrypt (encryptor, input, output);
- }
- catch (Exception e) {
- if (e.Message != "Input buffer contains insufficient data. ")
- Fail ("Rijndael_k256b128_ECB_Zeros: This isn't the expected exception: " + e.ToString ());
- }
- }
- public void TestRijndael_k256b128_ECB_PKCS7 ()
- {
- byte[] key = { 0x19, 0xC2, 0x2D, 0x12, 0x57, 0x2B, 0xEF, 0x0C, 0xA2, 0xC7, 0x26, 0x7E, 0x35, 0xAD, 0xC5, 0x12, 0x53, 0x5D, 0xEE, 0xD7, 0x69, 0xC3, 0xB4, 0x0D, 0x9B, 0xEF, 0x36, 0xF7, 0xB2, 0xF2, 0xB0, 0x37 };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0xCF, 0x8D, 0xBE, 0xE0, 0x41, 0xC6, 0xB9, 0xB5, 0x2D, 0x8A, 0x59, 0x92, 0x82, 0xF4, 0xE8, 0x74 };
- byte[] expected = { 0xAD, 0x99, 0x9A, 0xE2, 0x5B, 0xE7, 0xFB, 0x74, 0xE8, 0xAB, 0xEE, 0x5D, 0xCA, 0x0F, 0x0A, 0x7A, 0xAD, 0x99, 0x9A, 0xE2, 0x5B, 0xE7, 0xFB, 0x74, 0xE8, 0xAB, 0xEE, 0x5D, 0xCA, 0x0F, 0x0A, 0x7A, 0x8F, 0xAD, 0xBB, 0xC2, 0x18, 0xB8, 0xF0, 0xFF, 0x59, 0x7D, 0xF8, 0xF1, 0x6A, 0x21, 0x9C, 0xF3 };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 128;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("Rijndael_k256b128_ECB_PKCS7 Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("Rijndael_k256b128_ECB_PKCS7 b1==b2", block1, block2);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("Rijndael_k256b128_ECB_PKCS7 Decrypt", input, original);
- }
- public void TestRijndael_k256b128_CBC_None ()
- {
- byte[] key = { 0xE8, 0x74, 0x24, 0x77, 0x2B, 0xBE, 0x6C, 0x99, 0x2E, 0xFC, 0xB5, 0x85, 0xC9, 0xA1, 0xD7, 0x9C, 0x24, 0xF1, 0x86, 0x0B, 0xEA, 0xAB, 0xCB, 0x06, 0x47, 0x2E, 0x26, 0x6C, 0xAF, 0x24, 0x87, 0xA7 };
- byte[] iv = { 0x15, 0x7E, 0xA5, 0xE5, 0x47, 0xFA, 0x40, 0x30, 0x0A, 0xAA, 0x9E, 0x68, 0x8E, 0x4D, 0x2D, 0xA4 };
- byte[] expected = { 0xEF, 0x05, 0x1C, 0x5C, 0xEA, 0xED, 0x34, 0x28, 0x9E, 0x21, 0x9C, 0x2C, 0x96, 0xF5, 0xF7, 0xDA, 0x55, 0xD4, 0x88, 0x0A, 0x73, 0xF1, 0x8D, 0xBC, 0x8F, 0x17, 0x26, 0x86, 0x8A, 0xC1, 0x4B, 0x68, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 128;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("Rijndael_k256b128_CBC_None Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("Rijndael_k256b128_CBC_None Decrypt", input, original);
- }
- public void TestRijndael_k256b128_CBC_Zeros ()
- {
- byte[] key = { 0x50, 0x54, 0x8C, 0x92, 0xE5, 0xFD, 0x08, 0x03, 0xEA, 0x15, 0xBB, 0xB9, 0x39, 0x8B, 0x6E, 0xF0, 0xF5, 0x64, 0x49, 0x0E, 0x0F, 0x8F, 0x41, 0xF9, 0xA6, 0x1E, 0xD4, 0xD2, 0xB6, 0xF2, 0xB6, 0x4B };
- byte[] iv = { 0x32, 0x9B, 0x60, 0xF7, 0xBE, 0x0F, 0x5F, 0xA5, 0xD2, 0x7A, 0x1F, 0xB4, 0x01, 0x76, 0xD1, 0xCD };
- byte[] expected = { 0x6C, 0x55, 0xAD, 0x57, 0xEE, 0x78, 0x1D, 0x69, 0x82, 0x8D, 0xE5, 0x52, 0x4C, 0x76, 0xD7, 0xF1, 0xFA, 0xFC, 0xD1, 0x2D, 0xDC, 0x0F, 0xE4, 0x4F, 0xF0, 0xE5, 0xB0, 0x2B, 0x28, 0xBF, 0x07, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 128;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- // some exception can be normal... other not so!
- try {
- Encrypt (encryptor, input, output);
- }
- catch (Exception e) {
- if (e.Message != "Input buffer contains insufficient data. ")
- Fail ("Rijndael_k256b128_CBC_Zeros: This isn't the expected exception: " + e.ToString ());
- }
- }
- public void TestRijndael_k256b128_CBC_PKCS7 ()
- {
- byte[] key = { 0x8B, 0x8B, 0x4C, 0x04, 0x8C, 0x16, 0x16, 0x91, 0xBE, 0x79, 0x35, 0xF6, 0x26, 0x01, 0xF8, 0x06, 0x8F, 0xC7, 0x6D, 0xD6, 0xFE, 0xDE, 0xCF, 0xD8, 0xDC, 0xE1, 0x97, 0x9D, 0xA9, 0xD0, 0x96, 0x86 };
- byte[] iv = { 0xA0, 0xF5, 0x25, 0xE5, 0x17, 0xEA, 0x37, 0x18, 0x17, 0x56, 0x26, 0x1C, 0x63, 0x95, 0xC3, 0xAD };
- byte[] expected = { 0x42, 0x33, 0x8E, 0xDE, 0x2E, 0xDA, 0xC9, 0xC6, 0x97, 0xA2, 0xAE, 0xE1, 0x15, 0x00, 0xDE, 0x4A, 0x39, 0x0B, 0xEB, 0xC8, 0xF9, 0x9F, 0x00, 0x05, 0xCF, 0xB5, 0x32, 0x46, 0x91, 0xFC, 0x28, 0x23, 0xF4, 0xC5, 0xCE, 0x42, 0x63, 0x3F, 0x82, 0x7D, 0x2A, 0xC4, 0xB5, 0x09, 0x67, 0xC7, 0x33, 0x3F };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 128;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("Rijndael_k256b128_CBC_PKCS7 Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("Rijndael_k256b128_CBC_PKCS7 Decrypt", input, original);
- }
- /* Invalid parameters Rijndael_k256b128_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters Rijndael_k256b128_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters Rijndael_k256b128_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters Rijndael_k256b128_CFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters Rijndael_k256b128_CFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters Rijndael_k256b128_CFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters Rijndael_k256b128_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters Rijndael_k256b128_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters Rijndael_k256b128_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
- public void TestRijndael_k256b192_ECB_None ()
- {
- byte[] key = { 0xE3, 0x43, 0x35, 0xDB, 0xB7, 0xC8, 0x24, 0xBF, 0x25, 0xD2, 0xA3, 0xCD, 0x70, 0xEB, 0x6B, 0xB7, 0x6D, 0x64, 0xF4, 0xB8, 0xA0, 0x56, 0x52, 0xFB, 0x3A, 0x09, 0xD4, 0xD9, 0x4F, 0x09, 0x19, 0xAF };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0xDB, 0x11, 0xE4, 0x50, 0x12, 0x29, 0xC8, 0x63, 0x61, 0xEC, 0xFE, 0xD3, 0xFE, 0xA2, 0x19, 0xE0, 0xEC, 0x2F, 0x56, 0x69, 0xB7, 0x41, 0x56, 0xB0 };
- byte[] expected = { 0x66, 0xD0, 0x72, 0x3B, 0xFA, 0x3F, 0x27, 0x81, 0xB6, 0x91, 0x78, 0x7A, 0x4C, 0xD0, 0xA0, 0x4C, 0x93, 0x56, 0x51, 0xA3, 0xE0, 0x69, 0x63, 0xAF, 0x66, 0xD0, 0x72, 0x3B, 0xFA, 0x3F, 0x27, 0x81, 0xB6, 0x91, 0x78, 0x7A, 0x4C, 0xD0, 0xA0, 0x4C, 0x93, 0x56, 0x51, 0xA3, 0xE0, 0x69, 0x63, 0xAF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 192;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("Rijndael_k256b192_ECB_None Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("Rijndael_k256b192_ECB_None b1==b2", block1, block2);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("Rijndael_k256b192_ECB_None Decrypt", input, original);
- }
- public void TestRijndael_k256b192_ECB_Zeros ()
- {
- byte[] key = { 0xCF, 0xAC, 0xFC, 0x30, 0x6C, 0x01, 0x16, 0x8A, 0x82, 0x52, 0x52, 0xC0, 0xC6, 0xAC, 0x1E, 0x60, 0x93, 0x17, 0x0A, 0x0C, 0x87, 0xE1, 0x4A, 0x78, 0xD9, 0xA6, 0x6B, 0xAF, 0x24, 0xF7, 0x8F, 0xED };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0x99, 0x2B, 0x6B, 0x30, 0x56, 0x13, 0x2E, 0xE3, 0x3B, 0x2B, 0xC1, 0xA9, 0x4B, 0x3B, 0xD9, 0xC3, 0x7B, 0xA7, 0x4F, 0x26, 0xC9, 0x62, 0xC9, 0x66 };
- byte[] expected = { 0x22, 0x6B, 0xFA, 0x34, 0x8E, 0x09, 0xC2, 0xDF, 0xCA, 0x6C, 0xF5, 0x1F, 0xD2, 0xDC, 0x01, 0xC6, 0x3B, 0x73, 0x3F, 0x64, 0x91, 0x9F, 0xF6, 0xD3, 0x22, 0x6B, 0xFA, 0x34, 0x8E, 0x09, 0xC2, 0xDF, 0xCA, 0x6C, 0xF5, 0x1F, 0xD2, 0xDC, 0x01, 0xC6, 0x3B, 0x73, 0x3F, 0x64, 0x91, 0x9F, 0xF6, 0xD3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 192;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- // some exception can be normal... other not so!
- try {
- Encrypt (encryptor, input, output);
- }
- catch (Exception e) {
- if (e.Message != "Input buffer contains insufficient data. ")
- Fail ("Rijndael_k256b192_ECB_Zeros: This isn't the expected exception: " + e.ToString ());
- }
- }
- public void TestRijndael_k256b192_ECB_PKCS7 ()
- {
- byte[] key = { 0x17, 0xF9, 0x4A, 0x56, 0x22, 0x77, 0x20, 0x33, 0x48, 0xCB, 0x06, 0x86, 0x44, 0x02, 0xCF, 0x52, 0xDA, 0x22, 0x36, 0x07, 0xE9, 0x9F, 0x3A, 0x28, 0x3E, 0xCB, 0x49, 0x51, 0xA4, 0x67, 0x60, 0xF3 };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0x07, 0x77, 0x47, 0xC3, 0x49, 0x85, 0x7D, 0xB7, 0xED, 0xF3, 0x0D, 0x3F, 0x0F, 0xDC, 0xA6, 0x3E, 0x01, 0x53, 0x4D, 0x61, 0xEC, 0x06, 0xB4, 0xA0 };
- byte[] expected = { 0xA0, 0x34, 0x6F, 0xFD, 0x84, 0xA3, 0x54, 0xC0, 0x7E, 0xCC, 0x7D, 0x02, 0xE5, 0xDA, 0x79, 0x4E, 0xC6, 0xEB, 0xCE, 0x42, 0xD2, 0xBE, 0x68, 0x0F, 0xA0, 0x34, 0x6F, 0xFD, 0x84, 0xA3, 0x54, 0xC0, 0x7E, 0xCC, 0x7D, 0x02, 0xE5, 0xDA, 0x79, 0x4E, 0xC6, 0xEB, 0xCE, 0x42, 0xD2, 0xBE, 0x68, 0x0F, 0xBC, 0x22, 0x09, 0x5B, 0xFA, 0x92, 0x7E, 0xD8, 0xFF, 0x6A, 0xDD, 0x43, 0x63, 0x72, 0x23, 0xBA, 0xF9, 0xC8, 0x06, 0x3F, 0x51, 0xE8, 0x14, 0xE7 };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 192;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("Rijndael_k256b192_ECB_PKCS7 Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("Rijndael_k256b192_ECB_PKCS7 b1==b2", block1, block2);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("Rijndael_k256b192_ECB_PKCS7 Decrypt", input, original);
- }
- public void TestRijndael_k256b192_CBC_None ()
- {
- byte[] key = { 0x7A, 0x26, 0xAB, 0x32, 0x31, 0x49, 0x69, 0x3D, 0x68, 0x5A, 0xAC, 0x1B, 0x63, 0x85, 0x5A, 0x3D, 0xC4, 0xDE, 0xA8, 0x76, 0x00, 0x26, 0x78, 0x31, 0xB6, 0x30, 0xD8, 0xCB, 0x7E, 0xE7, 0xE9, 0x5B };
- byte[] iv = { 0x9D, 0x7B, 0xD5, 0x59, 0xCA, 0x42, 0xCB, 0x2F, 0x02, 0x65, 0xFE, 0x85, 0x63, 0xAE, 0x14, 0x4F, 0x69, 0xAA, 0xC2, 0xAF, 0x06, 0xF0, 0x48, 0x4F };
- byte[] expected = { 0x6C, 0x03, 0x84, 0x1C, 0x4E, 0xE0, 0x05, 0x67, 0xEA, 0x8D, 0x1C, 0x41, 0xFD, 0xC2, 0x90, 0x0E, 0xB9, 0xAA, 0xE5, 0xA0, 0x41, 0x62, 0xFE, 0xD8, 0x57, 0xA1, 0xCE, 0x33, 0x22, 0x09, 0xDB, 0x3B, 0xD7, 0x0A, 0x68, 0x61, 0x76, 0xB9, 0x8F, 0x7E, 0xE8, 0xD9, 0xA0, 0x46, 0x2B, 0x15, 0xC3, 0xF9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 192;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("Rijndael_k256b192_CBC_None Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("Rijndael_k256b192_CBC_None Decrypt", input, original);
- }
- public void TestRijndael_k256b192_CBC_Zeros ()
- {
- byte[] key = { 0x35, 0x14, 0xF8, 0xDB, 0xB0, 0x84, 0x94, 0xD3, 0xDD, 0xE1, 0xB3, 0x21, 0x44, 0xE2, 0x9C, 0x65, 0x0A, 0x4A, 0x28, 0x7C, 0xD7, 0xD4, 0x9F, 0x49, 0x05, 0x23, 0x2C, 0xB2, 0x65, 0x17, 0x44, 0x2E };
- byte[] iv = { 0xD8, 0xA5, 0x77, 0x5C, 0x54, 0x79, 0x57, 0xE2, 0xBD, 0xF7, 0xD1, 0xF1, 0x6F, 0x52, 0x99, 0xBE, 0x04, 0x5E, 0x75, 0x51, 0xA6, 0x7D, 0xB9, 0x88 };
- byte[] expected = { 0xC8, 0x93, 0x1E, 0xED, 0x3F, 0x9F, 0x79, 0x34, 0x6C, 0x3F, 0x99, 0x4A, 0x25, 0xAF, 0x86, 0xDF, 0xDF, 0x19, 0x65, 0xE8, 0xAD, 0x75, 0x43, 0x1B, 0xCD, 0x1B, 0x15, 0x23, 0xC4, 0x49, 0x07, 0x31, 0x3E, 0xA2, 0x34, 0x58, 0xA0, 0x82, 0x9F, 0xF8, 0xB7, 0xB1, 0xBE, 0x59, 0xF1, 0x09, 0x5E, 0x61, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 192;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- // some exception can be normal... other not so!
- try {
- Encrypt (encryptor, input, output);
- }
- catch (Exception e) {
- if (e.Message != "Input buffer contains insufficient data. ")
- Fail ("Rijndael_k256b192_CBC_Zeros: This isn't the expected exception: " + e.ToString ());
- }
- }
- public void TestRijndael_k256b192_CBC_PKCS7 ()
- {
- byte[] key = { 0x18, 0x60, 0x4C, 0x76, 0x3D, 0x08, 0x05, 0x18, 0x66, 0xA8, 0xA5, 0x59, 0x9E, 0xB1, 0x12, 0x83, 0x70, 0x81, 0x40, 0x82, 0x09, 0xE4, 0x36, 0x41, 0xBB, 0x72, 0x53, 0xF3, 0xB6, 0x23, 0xAE, 0xB9 };
- byte[] iv = { 0xA9, 0xC1, 0x7A, 0x1D, 0xAF, 0x14, 0xFA, 0x7D, 0xEF, 0x7F, 0xDE, 0x9E, 0xE9, 0xD6, 0x1D, 0x61, 0x46, 0x2B, 0xC9, 0x24, 0x40, 0x0A, 0xE9, 0x9C };
- byte[] expected = { 0x9B, 0xE4, 0x1F, 0x94, 0xB2, 0x6B, 0x3E, 0x70, 0x69, 0x18, 0xCD, 0x65, 0xB7, 0xD9, 0xD9, 0x8E, 0xBB, 0xDA, 0xED, 0x5C, 0x84, 0xBA, 0x52, 0x4C, 0xA2, 0x66, 0xB8, 0x20, 0xEC, 0xB4, 0x16, 0xF1, 0x4C, 0xA2, 0xD0, 0x5F, 0x48, 0xDF, 0xA1, 0xDA, 0xEF, 0x75, 0xA8, 0x02, 0xCA, 0x57, 0x2E, 0x61, 0x94, 0x6A, 0x63, 0xFF, 0xBF, 0x2D, 0x44, 0x29, 0x38, 0x24, 0x50, 0x16, 0xE4, 0x41, 0x12, 0xBB, 0xF6, 0x67, 0x0A, 0xCF, 0x0A, 0xC9, 0x89, 0x55 };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 192;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("Rijndael_k256b192_CBC_PKCS7 Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("Rijndael_k256b192_CBC_PKCS7 Decrypt", input, original);
- }
- /* Invalid parameters Rijndael_k256b192_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters Rijndael_k256b192_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters Rijndael_k256b192_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters Rijndael_k256b192_CFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters Rijndael_k256b192_CFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters Rijndael_k256b192_CFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters Rijndael_k256b192_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters Rijndael_k256b192_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters Rijndael_k256b192_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
- public void TestRijndael_k256b256_ECB_None ()
- {
- byte[] key = { 0x04, 0x93, 0xC7, 0x1A, 0x3A, 0x62, 0x1E, 0x8B, 0x82, 0x6A, 0x20, 0x26, 0x5E, 0x29, 0x15, 0x0D, 0xCB, 0xD9, 0x49, 0x8A, 0x3E, 0x91, 0xE0, 0x8C, 0xE0, 0x9D, 0x8E, 0x15, 0x43, 0xE3, 0x1F, 0x9A };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0x41, 0x3B, 0xE7, 0x01, 0x40, 0xB6, 0xB9, 0x54, 0x24, 0x38, 0x38, 0xB5, 0x8C, 0x90, 0x8D, 0x90, 0x9D, 0x68, 0xE6, 0x9C, 0x92, 0xCD, 0x95, 0x77, 0x96, 0xC6, 0xE8, 0xD5, 0xA5, 0x3E, 0xBD, 0xB9 };
- byte[] expected = { 0x2F, 0x30, 0x0F, 0xA2, 0x9C, 0x0E, 0xCA, 0x38, 0xD5, 0x43, 0xB6, 0xD4, 0xF9, 0x16, 0x65, 0xB8, 0xAA, 0x29, 0xB8, 0x16, 0xB7, 0x62, 0xE5, 0xFD, 0xC3, 0x4C, 0xA7, 0x7B, 0xC7, 0xF5, 0x5C, 0x1E, 0x2F, 0x30, 0x0F, 0xA2, 0x9C, 0x0E, 0xCA, 0x38, 0xD5, 0x43, 0xB6, 0xD4, 0xF9, 0x16, 0x65, 0xB8, 0xAA, 0x29, 0xB8, 0x16, 0xB7, 0x62, 0xE5, 0xFD, 0xC3, 0x4C, 0xA7, 0x7B, 0xC7, 0xF5, 0x5C, 0x1E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 256;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("Rijndael_k256b256_ECB_None Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("Rijndael_k256b256_ECB_None b1==b2", block1, block2);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("Rijndael_k256b256_ECB_None Decrypt", input, original);
- }
- public void TestRijndael_k256b256_ECB_Zeros ()
- {
- byte[] key = { 0x52, 0x21, 0xDF, 0x3C, 0x96, 0x67, 0x86, 0x28, 0x80, 0x97, 0x12, 0xBB, 0xDD, 0x80, 0xE1, 0x04, 0xC8, 0x4B, 0x12, 0x3E, 0x28, 0x3F, 0x32, 0x38, 0xC8, 0xA0, 0x12, 0xFA, 0xFE, 0x8C, 0x0C, 0xEC };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0xA9, 0x41, 0xB0, 0xE2, 0x23, 0x9A, 0x75, 0x56, 0x5F, 0x5D, 0xB8, 0x0B, 0xB1, 0xF1, 0x0F, 0xC2, 0x50, 0xBF, 0xA7, 0x3B, 0x8A, 0x26, 0xD4, 0x82, 0x33, 0xE1, 0x77, 0x84, 0xCC, 0x47, 0xCB, 0x85 };
- byte[] expected = { 0xB0, 0xC4, 0x5A, 0xDA, 0x21, 0x69, 0x9A, 0x80, 0xFC, 0xF4, 0xD1, 0xA5, 0xEE, 0x43, 0x44, 0x27, 0x4F, 0x42, 0x38, 0xFE, 0xC4, 0x2C, 0x75, 0x00, 0x60, 0x66, 0x1E, 0x86, 0xD0, 0xFC, 0x4B, 0x23, 0xB0, 0xC4, 0x5A, 0xDA, 0x21, 0x69, 0x9A, 0x80, 0xFC, 0xF4, 0xD1, 0xA5, 0xEE, 0x43, 0x44, 0x27, 0x4F, 0x42, 0x38, 0xFE, 0xC4, 0x2C, 0x75, 0x00, 0x60, 0x66, 0x1E, 0x86, 0xD0, 0xFC, 0x4B, 0x23, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 256;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- // some exception can be normal... other not so!
- try {
- Encrypt (encryptor, input, output);
- }
- catch (Exception e) {
- if (e.Message != "Input buffer contains insufficient data. ")
- Fail ("Rijndael_k256b256_ECB_Zeros: This isn't the expected exception: " + e.ToString ());
- }
- }
- public void TestRijndael_k256b256_ECB_PKCS7 ()
- {
- byte[] key = { 0xC6, 0x74, 0x58, 0xA6, 0xE0, 0xAD, 0xA2, 0x2F, 0x36, 0xC1, 0xD7, 0xAC, 0xAD, 0x8E, 0x66, 0x18, 0x8B, 0xEF, 0xBF, 0x1B, 0x75, 0xF0, 0xB0, 0x96, 0xBB, 0x07, 0xE9, 0x67, 0x25, 0x1B, 0xD0, 0x46 };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0x3B, 0x34, 0x5E, 0x47, 0xE3, 0x51, 0xC4, 0xE4, 0x9A, 0x66, 0xD6, 0x42, 0x1B, 0x45, 0xAB, 0x03, 0x35, 0x9A, 0x52, 0xD8, 0x1E, 0xA3, 0xC8, 0xD8, 0xBB, 0x3E, 0xD1, 0x35, 0x2C, 0x90, 0xB1, 0xC7 };
- byte[] expected = { 0x48, 0xD6, 0xD0, 0x25, 0xC7, 0x71, 0x0E, 0x10, 0xB9, 0x05, 0xE4, 0xC9, 0xEF, 0xAD, 0xB8, 0x2B, 0x14, 0xAF, 0x10, 0x53, 0x27, 0x8F, 0x32, 0x2C, 0x25, 0x9D, 0xCE, 0x64, 0x22, 0x52, 0x29, 0xCB, 0x48, 0xD6, 0xD0, 0x25, 0xC7, 0x71, 0x0E, 0x10, 0xB9, 0x05, 0xE4, 0xC9, 0xEF, 0xAD, 0xB8, 0x2B, 0x14, 0xAF, 0x10, 0x53, 0x27, 0x8F, 0x32, 0x2C, 0x25, 0x9D, 0xCE, 0x64, 0x22, 0x52, 0x29, 0xCB, 0xDF, 0x29, 0xD6, 0xDD, 0xFB, 0x89, 0x4B, 0xD7, 0x24, 0x88, 0x8E, 0x74, 0x95, 0x79, 0xBD, 0xFB, 0x80, 0xCF, 0x34, 0x7C, 0xEC, 0x2A, 0xDF, 0xBB, 0x18, 0xF6, 0xB6, 0x41, 0x00, 0xA5, 0x00, 0x55 };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 256;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("Rijndael_k256b256_ECB_PKCS7 Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("Rijndael_k256b256_ECB_PKCS7 b1==b2", block1, block2);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("Rijndael_k256b256_ECB_PKCS7 Decrypt", input, original);
- }
- public void TestRijndael_k256b256_CBC_None ()
- {
- byte[] key = { 0x2E, 0x1E, 0x55, 0x9B, 0xA8, 0x5A, 0x1D, 0x2A, 0x6B, 0x4D, 0x95, 0x8E, 0x7C, 0xFC, 0x33, 0xCE, 0x00, 0xA3, 0xFA, 0xCE, 0x9F, 0xF6, 0xED, 0x0C, 0xD5, 0x3C, 0xB0, 0xF4, 0x87, 0x26, 0x1E, 0x12 };
- byte[] iv = { 0xB2, 0xCC, 0xA6, 0x99, 0x96, 0x9C, 0xC1, 0x20, 0x2A, 0xB1, 0x00, 0x28, 0x85, 0xE1, 0xB7, 0x74, 0x66, 0x02, 0xF5, 0x69, 0xE3, 0x1F, 0xA4, 0xF4, 0xFB, 0x90, 0x3F, 0xB2, 0x7E, 0x56, 0xC9, 0x6E };
- byte[] expected = { 0x4D, 0x77, 0x53, 0xBE, 0xDB, 0xB7, 0x4D, 0x1B, 0x9B, 0x1F, 0x65, 0x7A, 0xF1, 0x8F, 0x40, 0x0D, 0x60, 0x46, 0x08, 0x8B, 0x36, 0x83, 0x91, 0x8E, 0xDC, 0x23, 0x48, 0x1F, 0x4B, 0xCB, 0x09, 0x31, 0xDB, 0x73, 0xA6, 0xF3, 0xDB, 0x98, 0x06, 0xE9, 0xFA, 0x72, 0x4F, 0xDC, 0x3A, 0xF1, 0x08, 0x7B, 0x42, 0x1E, 0xD3, 0xDB, 0x91, 0xC3, 0x2C, 0x3D, 0xD7, 0x79, 0x17, 0x2A, 0xE1, 0x3C, 0x21, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 256;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("Rijndael_k256b256_CBC_None Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("Rijndael_k256b256_CBC_None Decrypt", input, original);
- }
- public void TestRijndael_k256b256_CBC_Zeros ()
- {
- byte[] key = { 0xEE, 0x9F, 0xAB, 0x79, 0x11, 0x3F, 0x53, 0x56, 0x4C, 0xB4, 0xC3, 0x70, 0x29, 0x03, 0xB8, 0x26, 0x8C, 0x30, 0x2A, 0xD3, 0xF2, 0x1E, 0xA3, 0x42, 0xF4, 0xE6, 0x79, 0x5B, 0x0D, 0x93, 0xCF, 0x1B };
- byte[] iv = { 0xB0, 0x2A, 0x0F, 0x47, 0x4E, 0x47, 0xDB, 0x4A, 0xF2, 0xC7, 0xEB, 0xC3, 0xFA, 0xD3, 0x89, 0x0B, 0x46, 0x17, 0xDE, 0xB9, 0x18, 0x37, 0x6E, 0x83, 0x95, 0xD6, 0xF9, 0x25, 0xB5, 0xAC, 0x86, 0x9B };
- byte[] expected = { 0x6F, 0x0B, 0x2F, 0x3E, 0x9B, 0x07, 0xDE, 0x8B, 0xE9, 0xE7, 0xD7, 0x10, 0x09, 0xAF, 0x8E, 0x84, 0xB7, 0xBA, 0xD1, 0x79, 0x37, 0xF1, 0x25, 0xB6, 0xD7, 0xFC, 0xFB, 0x62, 0x83, 0x86, 0x8A, 0xD1, 0xC6, 0xDD, 0x98, 0x59, 0xE3, 0xEE, 0x9C, 0xA6, 0x73, 0x03, 0xE6, 0xB2, 0x72, 0xD0, 0x35, 0x39, 0xBB, 0x1C, 0x8F, 0x08, 0x8C, 0x70, 0x4C, 0x0C, 0xAD, 0xCB, 0x4F, 0x9D, 0xB7, 0x6A, 0x5F, 0xE9, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 256;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- // some exception can be normal... other not so!
- try {
- Encrypt (encryptor, input, output);
- }
- catch (Exception e) {
- if (e.Message != "Input buffer contains insufficient data. ")
- Fail ("Rijndael_k256b256_CBC_Zeros: This isn't the expected exception: " + e.ToString ());
- }
- }
- public void TestRijndael_k256b256_CBC_PKCS7 ()
- {
- byte[] key = { 0x63, 0x95, 0x5F, 0x23, 0xFE, 0x8B, 0x49, 0x09, 0xBD, 0x05, 0x0D, 0x47, 0xCE, 0x48, 0x86, 0x02, 0x58, 0x44, 0x78, 0x21, 0x28, 0x75, 0x2E, 0x3A, 0x80, 0xE4, 0x41, 0x97, 0x0F, 0xB8, 0xA4, 0xB1 };
- byte[] iv = { 0xE1, 0xC3, 0x6B, 0x5D, 0x4F, 0x86, 0x0D, 0x44, 0xD6, 0x73, 0x21, 0x50, 0x11, 0xD3, 0x41, 0x61, 0x33, 0x04, 0x1A, 0xF8, 0x50, 0x33, 0x93, 0x4A, 0x7F, 0x9F, 0x48, 0x27, 0x8C, 0x25, 0x90, 0x93 };
- byte[] expected = { 0x1F, 0x18, 0x81, 0x2B, 0xEA, 0xE1, 0x05, 0x56, 0xF5, 0x71, 0x73, 0x8C, 0x84, 0x9C, 0x46, 0xF9, 0x18, 0xEE, 0x08, 0xB1, 0x4B, 0x96, 0xC9, 0xC9, 0x70, 0xC8, 0x3B, 0xEC, 0x15, 0x40, 0x5C, 0xA0, 0x3A, 0xD1, 0x09, 0x0C, 0xD8, 0x6F, 0xAA, 0xF5, 0x34, 0x52, 0x3A, 0x51, 0x8F, 0x3A, 0xB0, 0x3E, 0xFB, 0x31, 0x43, 0x97, 0xA3, 0x05, 0xC6, 0xF2, 0x7F, 0x2A, 0xF0, 0x4F, 0xA8, 0x64, 0xE7, 0x06, 0xFB, 0x59, 0xD3, 0xFB, 0x9E, 0x72, 0x3B, 0x11, 0xEE, 0x88, 0xEC, 0x29, 0xB2, 0x51, 0xD9, 0x58, 0x42, 0x79, 0xFC, 0x35, 0xE2, 0xF1, 0x81, 0x45, 0x8F, 0x7E, 0xE1, 0xBA, 0x95, 0xC9, 0xDD, 0x76 };
- SymmetricAlgorithm algo = Rijndael.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 256;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("Rijndael_k256b256_CBC_PKCS7 Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("Rijndael_k256b256_CBC_PKCS7 Decrypt", input, original);
- }
- /* Invalid parameters Rijndael_k256b256_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters Rijndael_k256b256_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters Rijndael_k256b256_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters Rijndael_k256b256_CFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters Rijndael_k256b256_CFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters Rijndael_k256b256_CFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters Rijndael_k256b256_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters Rijndael_k256b256_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters Rijndael_k256b256_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
- public void TestTripleDES_k128b64_ECB_None ()
- {
- byte[] key = { 0x31, 0x29, 0x5A, 0x2D, 0x18, 0xDF, 0x78, 0xB1, 0xB3, 0x30, 0xB4, 0x2E, 0x08, 0x2A, 0xB5, 0x00 };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0xDE, 0x87, 0xFF, 0xA6, 0x30, 0x76, 0x39, 0x89 };
- byte[] expected = { 0x74, 0xD2, 0x61, 0x01, 0xF0, 0x86, 0x74, 0xE8, 0x74, 0xD2, 0x61, 0x01, 0xF0, 0x86, 0x74, 0xE8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = TripleDES.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("TripleDES_k128b64_ECB_None Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("TripleDES_k128b64_ECB_None b1==b2", block1, block2);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("TripleDES_k128b64_ECB_None Decrypt", input, original);
- }
- public void TestTripleDES_k128b64_ECB_Zeros ()
- {
- byte[] key = { 0xFB, 0xC1, 0xA8, 0x04, 0x47, 0x10, 0x09, 0x09, 0xA8, 0x3D, 0x97, 0x18, 0x11, 0x3C, 0x28, 0x80 };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0xA2, 0x1F, 0x63, 0x49, 0x33, 0xCA, 0xEE, 0xDA };
- byte[] expected = { 0xDB, 0x4E, 0x92, 0x3D, 0xE3, 0x26, 0x0B, 0x16, 0xDB, 0x4E, 0x92, 0x3D, 0xE3, 0x26, 0x0B, 0x16, 0xDB, 0x4E, 0x92, 0x3D, 0xE3, 0x26, 0x0B, 0x16 };
- SymmetricAlgorithm algo = TripleDES.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("TripleDES_k128b64_ECB_Zeros Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("TripleDES_k128b64_ECB_Zeros b1==b2", block1, block2);
- // also if padding is Zeros then all three blocks should be equals
- byte[] block3 = new byte[blockLength];
- Array.Copy (output, blockLength, block3, 0, blockLength);
- AssertEquals ("TripleDES_k128b64_ECB_Zeros b1==b3", block1, block3);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("TripleDES_k128b64_ECB_Zeros Decrypt", input, original);
- }
- public void TestTripleDES_k128b64_ECB_PKCS7 ()
- {
- byte[] key = { 0x78, 0x52, 0xAE, 0x73, 0x24, 0x0A, 0xDF, 0x80, 0x1A, 0xDE, 0x32, 0x90, 0x3C, 0x01, 0xBA, 0x12 };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0xF6, 0x11, 0x79, 0x5E, 0xEC, 0xDC, 0x5E, 0x19 };
- byte[] expected = { 0x83, 0xDE, 0x8A, 0xDA, 0x7A, 0x46, 0xDC, 0x07, 0x83, 0xDE, 0x8A, 0xDA, 0x7A, 0x46, 0xDC, 0x07, 0x4B, 0x79, 0x8C, 0x46, 0x0A, 0xB7, 0x40, 0x6C };
- SymmetricAlgorithm algo = TripleDES.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("TripleDES_k128b64_ECB_PKCS7 Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("TripleDES_k128b64_ECB_PKCS7 b1==b2", block1, block2);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("TripleDES_k128b64_ECB_PKCS7 Decrypt", input, original);
- }
- public void TestTripleDES_k128b64_CBC_None ()
- {
- byte[] key = { 0x9B, 0x97, 0x95, 0xA2, 0x6D, 0x90, 0x1D, 0xAE, 0xE8, 0xFC, 0xA1, 0xA2, 0x06, 0x6E, 0x75, 0xE8 };
- byte[] iv = { 0x52, 0xF8, 0x0E, 0xA9, 0x8C, 0xD9, 0x46, 0x63 };
- byte[] expected = { 0xD3, 0x37, 0x2D, 0x9B, 0x69, 0x35, 0xB7, 0x80, 0xD1, 0x13, 0xBB, 0xEB, 0x47, 0xB6, 0xDA, 0xF2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = TripleDES.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("TripleDES_k128b64_CBC_None Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("TripleDES_k128b64_CBC_None Decrypt", input, original);
- }
- public void TestTripleDES_k128b64_CBC_Zeros ()
- {
- byte[] key = { 0x21, 0x87, 0x57, 0xF4, 0xE5, 0xE9, 0x91, 0xC7, 0x3A, 0x64, 0x14, 0xF2, 0x2B, 0x06, 0x0E, 0x2E };
- byte[] iv = { 0x23, 0x86, 0x58, 0x7B, 0x49, 0x23, 0xF6, 0x7F };
- byte[] expected = { 0xEF, 0x1B, 0x0B, 0xDD, 0xD0, 0x07, 0x5E, 0x22, 0x9D, 0xB9, 0xCC, 0x52, 0xB4, 0xD9, 0x88, 0x1F, 0x5D, 0xE3, 0x51, 0x51, 0xBF, 0x7C, 0xB5, 0xB3 };
- SymmetricAlgorithm algo = TripleDES.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("TripleDES_k128b64_CBC_Zeros Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("TripleDES_k128b64_CBC_Zeros Decrypt", input, original);
- }
- public void TestTripleDES_k128b64_CBC_PKCS7 ()
- {
- byte[] key = { 0x06, 0x33, 0x4B, 0x5A, 0xF0, 0xC6, 0xAE, 0x71, 0x8C, 0x41, 0xB3, 0x72, 0x43, 0x4B, 0x82, 0x31 };
- byte[] iv = { 0x40, 0x7F, 0x60, 0x5B, 0x5C, 0x22, 0x8D, 0x5D };
- byte[] expected = { 0x9C, 0x3F, 0x6A, 0x1D, 0xBD, 0x92, 0x1A, 0xFA, 0xD4, 0xA5, 0xEA, 0xB3, 0x77, 0xA0, 0x8B, 0xB0, 0x7E, 0x11, 0xFA, 0xA9, 0x45, 0x46, 0x16, 0x33 };
- SymmetricAlgorithm algo = TripleDES.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("TripleDES_k128b64_CBC_PKCS7 Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("TripleDES_k128b64_CBC_PKCS7 Decrypt", input, original);
- }
- /* Invalid parameters TripleDES_k128b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters TripleDES_k128b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters TripleDES_k128b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
- public void TestTripleDES_k128b64_CFB8_None ()
- {
- byte[] key = { 0x49, 0x9D, 0x94, 0x9C, 0x79, 0xD9, 0xEE, 0x92, 0x75, 0xE8, 0x8C, 0x78, 0xE3, 0xB5, 0x49, 0x81 };
- byte[] iv = { 0x80, 0x0A, 0x45, 0x55, 0xCB, 0xC7, 0x17, 0xA1 };
- byte[] expected = { 0xA5, 0x0F, 0xFF, 0xE6, 0xA0, 0x59, 0x58, 0x81, 0xB0, 0xFE, 0x19, 0x40, 0xF4, 0x04, 0x0B, 0xE7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = TripleDES.Create ();
- algo.Mode = CipherMode.CFB;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 64;
- algo.FeedbackSize = 8;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("TripleDES_k128b64_CFB8_None Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("TripleDES_k128b64_CFB8_None Decrypt", input, original);
- }
- public void TestTripleDES_k128b64_CFB8_Zeros ()
- {
- byte[] key = { 0x47, 0xD4, 0x00, 0xC6, 0x0B, 0xCE, 0x0D, 0x6B, 0xD6, 0xEB, 0xBF, 0x74, 0xE3, 0xB9, 0x61, 0x14 };
- byte[] iv = { 0x63, 0xB1, 0xCE, 0xEF, 0x06, 0x14, 0xD6, 0x4B };
- byte[] expected = { 0x02, 0xB8, 0xB8, 0x49, 0xA8, 0x3B, 0x6B, 0x05, 0x74, 0x79, 0x91, 0xFE, 0x7B, 0x74, 0x0A, 0xF8, 0x95, 0x80, 0x5A, 0xF1, 0xE9, 0xD7, 0xD3, 0x32 };
- SymmetricAlgorithm algo = TripleDES.Create ();
- algo.Mode = CipherMode.CFB;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 64;
- algo.FeedbackSize = 8;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("TripleDES_k128b64_CFB8_Zeros Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("TripleDES_k128b64_CFB8_Zeros Decrypt", input, original);
- }
- public void TestTripleDES_k128b64_CFB8_PKCS7 ()
- {
- byte[] key = { 0x70, 0x9E, 0x39, 0x1A, 0x45, 0xA4, 0x18, 0x30, 0xAC, 0xE6, 0x1E, 0x0E, 0xD7, 0x43, 0x39, 0x5F };
- byte[] iv = { 0x26, 0xF3, 0x46, 0x6A, 0x35, 0xC8, 0xBF, 0x03 };
- byte[] expected = { 0x88, 0x21, 0x01, 0x82, 0x88, 0x2E, 0x93, 0xC5, 0xCD, 0xA2, 0xC9, 0x38, 0x45, 0x68, 0x91, 0x82, 0xA5, 0x78, 0x6B, 0x08, 0x3F, 0x7C, 0xB8, 0x5F };
- SymmetricAlgorithm algo = TripleDES.Create ();
- algo.Mode = CipherMode.CFB;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 64;
- algo.FeedbackSize = 8;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("TripleDES_k128b64_CFB8_PKCS7 Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("TripleDES_k128b64_CFB8_PKCS7 Decrypt", input, original);
- }
- /* Invalid parameters TripleDES_k128b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters TripleDES_k128b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters TripleDES_k128b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
- public void TestTripleDES_k192b64_ECB_None ()
- {
- byte[] key = { 0x02, 0xFE, 0x15, 0x59, 0xD7, 0xE9, 0xB5, 0x2A, 0xA7, 0x9B, 0xB3, 0xA6, 0xFA, 0xAA, 0xC7, 0x97, 0xD4, 0x1B, 0xE4, 0x2D, 0xE4, 0xC5, 0x89, 0xC2 };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0x13, 0xBF, 0xF3, 0xA0, 0xD3, 0xA1, 0x2F, 0x23 };
- byte[] expected = { 0xC8, 0x09, 0x6E, 0xD6, 0xC8, 0xD8, 0xF3, 0x6A, 0xC8, 0x09, 0x6E, 0xD6, 0xC8, 0xD8, 0xF3, 0x6A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = TripleDES.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("TripleDES_k192b64_ECB_None Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("TripleDES_k192b64_ECB_None b1==b2", block1, block2);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("TripleDES_k192b64_ECB_None Decrypt", input, original);
- }
- public void TestTripleDES_k192b64_ECB_Zeros ()
- {
- byte[] key = { 0x0B, 0xB5, 0x02, 0xE8, 0xC3, 0x2E, 0x24, 0xD9, 0xF0, 0x29, 0x15, 0x10, 0x19, 0x88, 0xFC, 0xD2, 0x60, 0xCA, 0x30, 0x51, 0x0D, 0xD6, 0x80, 0xAC };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0xF6, 0xC5, 0xBD, 0xA2, 0x4D, 0xA8, 0x19, 0x78 };
- byte[] expected = { 0xE0, 0x52, 0xCB, 0xC6, 0xBB, 0x43, 0x8F, 0x3B, 0xE0, 0x52, 0xCB, 0xC6, 0xBB, 0x43, 0x8F, 0x3B, 0xE0, 0x52, 0xCB, 0xC6, 0xBB, 0x43, 0x8F, 0x3B };
- SymmetricAlgorithm algo = TripleDES.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("TripleDES_k192b64_ECB_Zeros Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("TripleDES_k192b64_ECB_Zeros b1==b2", block1, block2);
- // also if padding is Zeros then all three blocks should be equals
- byte[] block3 = new byte[blockLength];
- Array.Copy (output, blockLength, block3, 0, blockLength);
- AssertEquals ("TripleDES_k192b64_ECB_Zeros b1==b3", block1, block3);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("TripleDES_k192b64_ECB_Zeros Decrypt", input, original);
- }
- public void TestTripleDES_k192b64_ECB_PKCS7 ()
- {
- byte[] key = { 0x41, 0xAD, 0x00, 0xE4, 0x53, 0x0A, 0x09, 0x8C, 0x1F, 0x86, 0x91, 0x46, 0x41, 0xEC, 0xE3, 0x70, 0x35, 0xE5, 0x65, 0x10, 0x0D, 0x38, 0x4F, 0xE3 };
- // not used for ECB but make the code more uniform
- byte[] iv = { 0xB0, 0x71, 0x70, 0xFC, 0x57, 0xC2, 0x26, 0xF9 };
- byte[] expected = { 0xA3, 0xB3, 0x91, 0x00, 0x99, 0x7A, 0x15, 0xB4, 0xA3, 0xB3, 0x91, 0x00, 0x99, 0x7A, 0x15, 0xB4, 0x53, 0x35, 0xE6, 0x2D, 0x0D, 0xD1, 0x16, 0xE6 };
- SymmetricAlgorithm algo = TripleDES.Create ();
- algo.Mode = CipherMode.ECB;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("TripleDES_k192b64_ECB_PKCS7 Encrypt", expected, output);
- // in ECB the first 2 blocks should be equals (as the IV is not used)
- byte[] block1 = new byte[blockLength];
- Array.Copy (output, 0, block1, 0, blockLength);
- byte[] block2 = new byte[blockLength];
- Array.Copy (output, blockLength, block2, 0, blockLength);
- AssertEquals ("TripleDES_k192b64_ECB_PKCS7 b1==b2", block1, block2);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("TripleDES_k192b64_ECB_PKCS7 Decrypt", input, original);
- }
- public void TestTripleDES_k192b64_CBC_None ()
- {
- byte[] key = { 0xA5, 0xA5, 0x3B, 0x8E, 0x59, 0x5B, 0xDD, 0xEC, 0x15, 0x22, 0x95, 0x53, 0xCB, 0xEC, 0xE3, 0x63, 0x78, 0x25, 0xF5, 0xE5, 0x52, 0xAD, 0x50, 0x1A };
- byte[] iv = { 0xBD, 0x69, 0xAC, 0xA6, 0xCF, 0x17, 0xFC, 0x8A };
- byte[] expected = { 0xA6, 0xA8, 0x8E, 0x09, 0xCF, 0xD2, 0x66, 0x4A, 0x20, 0xE8, 0xC3, 0x56, 0x8F, 0x2F, 0x42, 0x75, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = TripleDES.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("TripleDES_k192b64_CBC_None Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("TripleDES_k192b64_CBC_None Decrypt", input, original);
- }
- public void TestTripleDES_k192b64_CBC_Zeros ()
- {
- byte[] key = { 0x40, 0x3D, 0xEC, 0xE5, 0xB4, 0x2A, 0x4B, 0x5E, 0x81, 0x88, 0x3A, 0x53, 0x3F, 0xFD, 0xE7, 0x55, 0x50, 0x21, 0xAA, 0x0A, 0xB4, 0x3B, 0x26, 0xC0 };
- byte[] iv = { 0x09, 0x50, 0xF5, 0x6F, 0x18, 0xD1, 0x4C, 0x9E };
- byte[] expected = { 0x85, 0xFA, 0xBF, 0x39, 0x5C, 0x17, 0x13, 0xF1, 0x27, 0x47, 0x17, 0x97, 0xBA, 0xCD, 0x69, 0x8E, 0x0D, 0x7D, 0xC5, 0xE2, 0x8F, 0xDF, 0xFC, 0x2B };
- SymmetricAlgorithm algo = TripleDES.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("TripleDES_k192b64_CBC_Zeros Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("TripleDES_k192b64_CBC_Zeros Decrypt", input, original);
- }
- public void TestTripleDES_k192b64_CBC_PKCS7 ()
- {
- byte[] key = { 0x31, 0x9E, 0x55, 0x57, 0x3F, 0x77, 0xBC, 0x27, 0x79, 0x45, 0x7E, 0xAA, 0x4F, 0xF1, 0x2E, 0xBB, 0x98, 0xAE, 0xFD, 0xBE, 0x22, 0xB8, 0x69, 0xD9 };
- byte[] iv = { 0xF7, 0xD8, 0x8E, 0xB2, 0xC5, 0x5F, 0x49, 0x91 };
- byte[] expected = { 0x0D, 0xB8, 0xC7, 0x8F, 0x89, 0x26, 0x42, 0x50, 0x5E, 0x3A, 0x3B, 0x4D, 0xC8, 0x0E, 0x7E, 0x0F, 0xDA, 0x79, 0x37, 0x89, 0x2A, 0xF6, 0x10, 0x76 };
- SymmetricAlgorithm algo = TripleDES.Create ();
- algo.Mode = CipherMode.CBC;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 64;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("TripleDES_k192b64_CBC_PKCS7 Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("TripleDES_k192b64_CBC_PKCS7 Decrypt", input, original);
- }
- /* Invalid parameters TripleDES_k192b64_CTS_None. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters TripleDES_k192b64_CTS_Zeros. Why? Specified cipher mode is not valid for this algorithm. */
- /* Invalid parameters TripleDES_k192b64_CTS_PKCS7. Why? Specified cipher mode is not valid for this algorithm. */
- public void TestTripleDES_k192b64_CFB8_None ()
- {
- byte[] key = { 0x6C, 0x11, 0xA9, 0xC8, 0x04, 0xB3, 0x74, 0x8A, 0xA0, 0xC7, 0x43, 0x9A, 0x1F, 0x4C, 0x79, 0x08, 0x4D, 0xB4, 0x7B, 0xAC, 0xA2, 0xF8, 0x2C, 0x22 };
- byte[] iv = { 0x2E, 0xF8, 0x02, 0x62, 0x15, 0xE2, 0x8F, 0xB1 };
- byte[] expected = { 0x95, 0x55, 0x48, 0xF1, 0x6D, 0x6F, 0x36, 0x25, 0xAE, 0x02, 0x0B, 0x6E, 0xC3, 0x04, 0xC5, 0x93, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
- SymmetricAlgorithm algo = TripleDES.Create ();
- algo.Mode = CipherMode.CFB;
- algo.Padding = PaddingMode.None;
- algo.BlockSize = 64;
- algo.FeedbackSize = 8;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("TripleDES_k192b64_CFB8_None Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("TripleDES_k192b64_CFB8_None Decrypt", input, original);
- }
- public void TestTripleDES_k192b64_CFB8_Zeros ()
- {
- byte[] key = { 0x34, 0x38, 0x7F, 0x40, 0xBA, 0x64, 0x88, 0xAC, 0x50, 0xE5, 0x0D, 0x9D, 0xC4, 0x0B, 0xDF, 0xE8, 0xB7, 0xCB, 0x9D, 0x38, 0xFD, 0x4E, 0x17, 0xDA };
- byte[] iv = { 0xC0, 0x32, 0xAE, 0xA8, 0xEB, 0x67, 0x74, 0xC4 };
- byte[] expected = { 0x8A, 0xE3, 0xAD, 0x43, 0x06, 0xAC, 0xC7, 0xE7, 0xCC, 0x03, 0xCE, 0xB1, 0x8F, 0x9F, 0x7A, 0x9E, 0xEB, 0x05, 0x74, 0x04, 0xF4, 0xFD, 0x76, 0x51 };
- SymmetricAlgorithm algo = TripleDES.Create ();
- algo.Mode = CipherMode.CFB;
- algo.Padding = PaddingMode.Zeros;
- algo.BlockSize = 64;
- algo.FeedbackSize = 8;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("TripleDES_k192b64_CFB8_Zeros Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("TripleDES_k192b64_CFB8_Zeros Decrypt", input, original);
- }
- public void TestTripleDES_k192b64_CFB8_PKCS7 ()
- {
- byte[] key = { 0xBC, 0x48, 0x95, 0x9F, 0x13, 0xFF, 0xCB, 0x33, 0x6D, 0xA5, 0x84, 0x93, 0x33, 0x54, 0xAD, 0xF4, 0x5F, 0x99, 0xA3, 0x0F, 0x0E, 0x91, 0x88, 0x0E };
- byte[] iv = { 0x0E, 0xC5, 0xA8, 0xB2, 0xDD, 0x83, 0xAE, 0x8C };
- byte[] expected = { 0xB5, 0x72, 0x20, 0x82, 0x45, 0x70, 0x83, 0xE5, 0xF0, 0xA6, 0xFC, 0xFC, 0xB6, 0xF4, 0x7D, 0x3B, 0x71, 0x94, 0x2A, 0x9F, 0x01, 0x46, 0x90, 0x56 };
- SymmetricAlgorithm algo = TripleDES.Create ();
- algo.Mode = CipherMode.CFB;
- algo.Padding = PaddingMode.PKCS7;
- algo.BlockSize = 64;
- algo.FeedbackSize = 8;
- int blockLength = (algo.BlockSize >> 3);
- byte[] input = new byte [blockLength * 2 + (blockLength >> 1)];
- byte[] output = new byte [blockLength * 3];
- ICryptoTransform encryptor = algo.CreateEncryptor(key, iv);
- Encrypt (encryptor, input, output);
- AssertEquals ("TripleDES_k192b64_CFB8_PKCS7 Encrypt", expected, output);
- byte[] reverse = new byte [blockLength * 3];
- ICryptoTransform decryptor = algo.CreateDecryptor(key, iv);
- Decrypt (decryptor, output, reverse);
- byte[] original = new byte [input.Length];
- Array.Copy (reverse, 0, original, 0, original.Length);
- AssertEquals ("TripleDES_k192b64_CFB8_PKCS7 Decrypt", input, original);
- }
- /* Invalid parameters TripleDES_k192b64_OFB8_None. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters TripleDES_k192b64_OFB8_Zeros. Why? Output feedback mode (OFB) is not supported by this implementation. */
- /* Invalid parameters TripleDES_k192b64_OFB8_PKCS7. Why? Output feedback mode (OFB) is not supported by this implementation. */
- // Number of test cases: 189
- // Number of invalid (non-generated) test cases: 171
- }
- }
|