Asymetrický šifrovací algoritmus

Původ

W.DiffieandM.Hellmanpublishedanarticle"NewDirectioninCryptography"inIEEETrans.onInformationin1976,andproposedthat"asymmetriccryptographyispublicTheconceptof"keycryptosystem"hascreatedanewdirectionincryptographyresearch

Pracovní princip

1.AwantstosendinformationtoB,andAandBmusthaveapairoffunctions.Publicandprivatekeysforencryptionanddecryption.

2.A'soukromý klíč je tajný a A'veřejný klíč je sdělován B;B'soukromý klíč je tajný a B'veřejný klíč je označen A.

3.Když chce odeslat zprávu B,použije veřejný klíč B k zašifrování zprávy, protože zná veřejný klíč B.

4.Pošlete tuto zprávu B (zpráva byla zašifrována veřejným klíčem B).

5.AfterBreceivesthismessage,BuseshisprivatekeytodecryptA'smessage.Allotherpeoplewhoreceivethismessagecannotdecryptit,becauseonlyBhasB'sprivatekey.

Hlavní aplikace

Asymmetricencryption(publickeyencryption):Referstoencryptionalgorithmsthatusedifferentkeysforencryptionanddecryption,alsoknownaspublicandprivatekeyencryption.Supposethattwouserswanttoencryptandexchangedata,andthetwopartiesexchangepublickeys.Whenusing,onepartyusestheotherparty'spublickeytoencrypt,andtheotherpartycanuseitsownprivatekeytodecrypt.Iftherearenusersinanenterprise,theenterpriseneedstogeneratenpairsofkeysanddistributenpublickeys.SupposeAusesB'spublickeytoencryptamessageandsignswithA'sprivatekey.Afterreceivingthemessage,BfirstverifiesthesignaturewithA'spublickey,andthendecryptsthemessagewithhisprivatekeyafterconfirmation.Sincethepublickeycanbedisclosed,usersonlyneedtokeeptheirprivatekeys,sothedistributionofencryptionkeyswillbecomeverysimple.Atthesametime,becauseeachuser'sprivatekeyisunique,otheruserscannotonlyusethesender'spublickeytoverifythesourceoftheinformation,butalsousedigitalsignaturestoensurethatthesendercannotdenythattheinformationhasbeensent.Thedisadvantageofasymmetricencryptionisthattheencryptionanddecryptionspeedismuchslowerthansymmetricencryption.Insomeextremecases,itcanevenbe1000timesslowerthansymmetricencryption.

DSACryptoServiceProviderRSACryptoServiceProvider

//Šifrování

UnicodeEncodingencoding=newUnicodeEncoding();

byte[]PasswordBytes=encoding.GetBytes(password);//Převést heslo na bytový paprsek RSACryptoServiceProvidercrypt=newRSACryptoServiceProvider();//Šifrovací goritmus RSA,asymetrickéByteshesla=crypt.Encrypt(heslo,kteréžtobytnépolevšifrovanédatasešifrují.

stringkey=crypt.ToXmlString(true);//TheoutputkeyisastringinXMLformatandcontainstheprivatekey.Thisstringshouldbeplacedasafieldinthedatabasetablewiththeuser’spasswordTogether.

//Dešifrování

RSACryptoServiceProvidercrypt=newRSACryptoServiceProvider();//Akeypairhasbeenrandomlygenerated

crypt.Clear();//Zničte aktuální pár klíčů

crypt.FromXmlString(klíč)//Zadejte pár klíčů,klíč je formát XML načtený z pole databázové tabulky, tedy pole klíčePasswordBytes=crypt.Decrypt(password,false);//Dešifrováníbytearraya vrácení původního hesla uživateli

Onefeatureoftheabovemethodisthateachusercorrespondstoakeypair(includingpublicandprivatekeys),Theyareallrandomlygenerated,sotheyarealldifferent.Buttheshortcomingisalsoveryobvious,thatis,thekeyisstoredinthedatabase,ifthedatabaseiscompromised,thekeywillbeleaked.

Anothermethodistorandomlygenerateakeypair(includingpublickeyandprivatekey)accordingtotheabovemethod,exportitthroughtheToXmlString(true)method,andthenputthekeyinXMLstringformatGototheAppSettingnodeoftheWeb.configfileofyourWebprogram,andthenreadthekeythroughtheFromXmlString(key)method,whichmeansthatalluserpasswordsareencryptedanddecryptedwiththesamekeypair.

Hlavní funkce

Theasymmetricencryptionsystemdoesnotrequirethecommunicationpartiestopassthekeyinadvanceorhaveanyagreementtocompleteconfidentialcommunication,andthekeymanagementisconvenient,whichcanpreventcounterfeitinganddenialTherefore,itismoresuitablefortheconfidentialcommunicationrequirementsinnetworkcommunication.

Hlavní algoritmy

RSA,Elgamal,knapsackalgorithm,Rabin,D-H,ECC(elipticcurveencryptiongorithm).

ThemostwidelyusedistheRSAalgorithm.Elgamalisanothercommonlyusedasymmetricencryptionalgorithm.

ElgamalwasinventedbyTaherElgamalin1985.ItisbasedontheDiffieˉHellmankeyexchangealgorithm,whichenablesbothcommunicatingpartiestoderivethesecretkeyvaluethatonlytheyknowthroughpubliccommunication[DiffieˉHellman].DiffieˉHellmanwasinventedbyWhitfieldDiffieandMartinHellmanin1976.Itisregardedasthefirstasymmetricencryptionalgorithm.ThedifferencebetweenDiffieˉHellmanandRSAisthatDiffieˉHellmanisnotanencryptionalgorithm,itjustgeneratesasecretvaluethatcanbeusedasasymmetrickey..IntheDiffieˉHellmankeyexchangeprocess,thesenderandthereceiverrespectivelygenerateasecretrandomnumber,andderivethepublicvaluefromtherandomnumber,andthenthetwopartiesexchangethepublicvalue.ThebasisoftheDiffieˉHellmanalgorithmistheabilitytogenerateasharedkey.Aslongasthepublicvalueisexchanged,bothpartiescanusetheirownprivatenumberandtheother'spublicvaluetogenerateasymmetrickey,whichiscalledasharedkey.Forbothparties,thesymmetrickeyisthesameandcanbeusedtousesymmetricencryption.Algorithmtoencryptdata.

ComparedwithRSA,oneoftheadvantagesofDiffieˉHellmanisthatitusesanewsetofvalues​​eachtimethekeyisexchanged.WhenusingtheRSAalgorithm,iftheattackerobtainstheprivatekey,thenhecannotonlydecryptMessagesinterceptedbeforecanalsodecryptallmessagesafterwards.However,RSAcanpreventman-in-the-middleattacksthroughauthentication(suchasusingX.509digitalcertificates),butDiffieHellmanisveryvulnerabletoman-in-the-middleattacks.

Rozdíl v algoritmu

NonSymmetricencryptionalgorithmDifferencefromsymmetricencryptionalgorithm

First,thekeyvalueusedformessagedecryptionisdifferentfromthekeyvalueusedformessageencryption;

Secondly,theasymmetricencryptionalgorithmisthousandsoftimesslowerthanthesymmetricencryptionalgorithm,butitprotectsIntermsofcommunicationsecurity,asymmetricencryptionalgorithmshavetheadvantagethatsymmetricencryptionisdifficulttoachieve.

Toillustratethisadvantage,anexampleofasymmetricencryptionalgorithmisusedtoemphasize:

AliceusesthekeyKtoencryptthemessageandsendsittoBob.AfterBobreceivestheencryptedmessage,UsethekeyKtodecryptittorestoretheoriginalmessage.Thereisaquestionhere,thatis,howdoesAlicesendthekeyvalueusedtoencryptthemessagetoBob?TheansweristhatwhenAlicesendsthekeyvaluetoBob,itmustpassthroughanindependentsecurecommunicationchannel(thatis,noonecanlistentothechannelCommunication).

Thisneedtouseanindependentsecurechanneltoexchangesymmetricencryptionalgorithmkeyswillcausemoreproblems:

First,thereisanindependentsecurechannel,butthebandwidthofthesecurechannelislimited.,Youcan’tdirectlyuseittosendtheoriginalmessage.

Secondly,AliceandBobcannotdeterminehowlongtheirkeyvaluecanbekeptwithoutrevealing(thatis,notknownbyothers)andwhentoexchangeanewkeyvalue

Ofcourse,TheseproblemsarenotonlyencounteredbyAlice,Bobandeveryoneelsewillencounterthem,theyallneedtoexchangekeysanddealwiththesekeymanagementproblems(infact,X9.17isaDESkeymanagementANSIstandard[ANSIX9.17]).IfAlicewantstosendmessagestohundredsofpeople,thenthingswillbeevenmoretroublesome.Shemustuseadifferentkeyvaluetoencrypteachmessage.Forexample,tosendanotificationto200people,Aliceneedstoencryptthemessage200timesandencryptthemessageonceforeachrecipient.Obviously,inthiscase,thecostofusingasymmetricencryptionalgorithmforsecurecommunicationisconsiderable.

Themainadvantageofasymmetricencryptionalgorithmsistousetwokeyvalues​​insteadofone:onekeyvalueisusedtoencryptthemessage,andtheotherkeyvalueisusedtodecryptthemessage.Thesetwokeyvalues​​aregeneratedinthesameprocessandarecalledakeypair.Thekeyusedtoencryptthemessageiscalledthepublickey,andthekeyusedtodecryptthemessageiscalledtheprivatekey.Messagesencryptedwithapublickeycanonlybedecryptedwiththecorrespondingprivatekey.Theprivatekeyisknowntonooneexcepttheholder,whilethepublickeycanbesentthroughaninsecurechannelorpublishedinadirectory.

AliceneedstosendaconfidentialdocumenttoBobviaemail.First,BobusesemailtosendhispublickeytoAlice.ThenAliceencryptsthedocumentwithBob'spublickeyandsendstheencryptedmessagetoBobviaemail.SinceanymessageencryptedwithBob'spublickeycanonlybedecryptedwithBob'sprivatekey,evenifthesnoopknowsBob'spublickey,themessageisstillsafe.AfterBobreceivestheencryptedmessage,hedecryptsitwithhisprivatekeytorestoretheoriginaldocument.

Související články
HORNÍ