-
RSA Algorithm- Data Analyzing For Asset. 2020. 12. 27. 02:20
RSA Encryption 123456789101112131415161718192021222324252627282930313233343536#public key(RSA) 알고리즘from Crypto.PublicKey import RSA#Private key와 Public key 쌍을 생성한다.#Private key는 소유자가 보관하고, Public key는 공개한다.keyPair = RSA.generate(2048)privKey = keyPair.exportKey() #키 소유자 보관용pubKey = keyPair.publickey() #외부 공개용#keyPair의 p,q,e,d를 확인해 본다.keyObj = RSA.importKey(privKey)print("p = ", keyObj.p)print("q = ", keyObj.q)print("e = ", keyObj.e)print("d = ", keyObj.d)#암호화할 원문plainText = "This is Plain text, It will be encrypted using RSA."print()print("원문 :")print(plainText)#공개키로 원문을 암호화한다.cipherText = pubKey.encrypt(plainText.encode(), 10)print("\n")print("암호문 : ")print(cipherText[0].hex())#private key를 소유한 수신자는 자신의 private key로 암호문을 해독한다.#pubkey와 쌍을 이루는 privKey만이 이 암호문을 해독할 수 있다.key = RSA.importKey(privKey)plainText2 = key.decrypt(cipherText)plainText2 = plainText2.decode()print("\n")print("해독문: ")print(plainText2)cs p = 131775797844047590688734608412378407760957637768005148276901514146025436722218797798941664304727759110374978158391514648167094186945908511054286135783276708522653044348815317736224390743752271539298552628031374034738803606046476742057393258732486594966882299539187733647117065782793621955305921148553079042461 q = 156191518479368785845898316786933128755238429005981976549831341110806788597059823747941016658235453918824285445540629446344550187967595216414127017136534516356796047640268403340767674381939889980536074993630016719130663296392452962416189686222139622722835530917818995120086243841314914457733860738881732104119 e = 65537 d = 17713992154396023618767056442903086686388560257861027834482381858827990644105973824350929977609643285490143698016439280902906335293963790120076047798115511982636536943005679091623522958032919638514519098195857579762461655113420282554454509078127572736233291272367180113760188636178351550894145064288974222620749475630474454536314369673796066912956187673876701461790472844109348605600108450694443080301131422892562526704492874098869314933240434824074575495032049559058306009997880492829889793716897015427458234837381000550736899785956723981659494719914626094960353647617496367301810596497294810323890991579835558579233
원문 : This is Plain text, It will be encrypted using RSA.
암호문 : 1163b66870a492af5275bdcd49791cbf036055af4d7ed91b34d05604a59500cd21bb54e7f04b51a57c82eb710f8ade8a7f5747040de90086091dbdeeda39e5471165f9f9cb50bcf34d3d0182b7504cbad5c6aa9ff8ccd684d2320296826218fd9bae2ae469743ded61ab1e526c15027e06dadb05894dfe5da9faf3869a0e5051573518bdf0ff7eda6d93446151aab22dcaee08ea248d44beb8733b9b914198ad24372d3f89e16208a91291476c3cd2ac2e02d93c45caefd1c8b358c850a0698ab7c7fa42a0f2a5d75a83e1091abc792915c3a14554cfc5749fff2878cc072d2dd6bace66ee2b64422ca8def53a341c1a0ec4f49bbdba33663e3c67f876e07483
해독문: This is Plain text, It will be encrypted using RSA.
'- Data Analyzing For Asset.' 카테고리의 다른 글
[Data Science] Machine Learning (0) 2021.02.01 [Data Science] Analyzing Data (2) 2021.01.18 [Image Processing] - Finding a person. (0) 2021.01.14 [Data Processing] - 각 지역별 인구구조 분석(그래프 별) (0) 2021.01.07 - AES : 대칭키 암호 절차 Sample (0) 2020.12.25