Learn Blockchain | Part 6 #4 | Implementing Multiple Encryption Algorithms Using Python | SHA 256 & RSA

NUR ARIF
1 min readJun 22, 2022

SHA 256

Currently, the most popular use of SHA 2 is SHA 256 bit which is the standard to get an A+ SSL configuration on Qlabs SSL with a very high level of security. So SHA 2 and SHA 256 are one and there is no difference. SHA 256 is part of SHA 2. This SHA 2 will relate to the hashing algorithm that will be used on the SSL root certificate.

an example of its use using python

from Crypto.Hash import SHA256

data = b'I will encrypt this data'
hasher = SHA256.new()
hasher.update(data)
result = hasher.hexdigest()

print(result)

Output :

d6f845f9530aea597c0d8dd2376cb1b8e711e725d90dbc2dafbe05bb1beeb560

RSA (Rivest–Shamir–Adleman)

RSA (Rivest–Shamir–Adleman) is the most popular algorithm for generating public keys in the world. This algorithm has survived attacks for more than 30 years and is therefore considered quite secure by data security system standards. This algorithm is commonly used in securing confidential data (encryption) and authentication (digital signature). RSA also uses private and public keys during encryption and decryption.

an example of its use using python

from Crypto.PublicKey import RSA

# encrypt
secret_code = "thiskeyhhhhh"
key = RSA.generate(1024)
private_key = key.export_key(passphrase=secret_code, pkcs=8,
protection="scryptAndAES128-CBC")
public_key = key.publickey().export_key()

print(private_key)
print(public_key)

Output

b’ — — -BEGIN ENCRYPTED PRIVATE KEY — — -\nMIIC1TBPBgkqhkiG9w0BBQ0wQjAhBgkrBgEEAdpHBAswFAQIBDKOAYWwt54CAkAA\nAgEIAgEBMB0GCWCGSAFlAwQBAgQQGFdA+m719RfrDlgxglKN/gSCAoDGp/X1gCeC\n7JRC5aHJ/RYGsxyqhZDza0Yib7o8+tUAw9C1Ov2WPKV0YlPrw/dm9TvzmDbUxw6m\nDCCglMa4O5NmgrOsla3aFPh/oxkw2aXreclb3pXzzUM53wzFNSv8u39LoMDW0hsR\nttrVEN4hZsC0eM+fF3DETgBsbyRP/K09Vx1CqROmPudoEs/s2qreo3wu3zhIsgQg\n0MA3UdOvra2FEDnkS6n87lRCcbpAljg+eN/4G2bveuX8u972Il7CG9t0g/LfAbAw\n6jQwypx6If2Q7eJY1P8MP/ErC1AhddJIscdOpZU4Exty0zvnRNmaGlJZ41Sszyb8\nibCewUmwQinb34ykX8rPZnPWfibA/FfG8m41A+2CLvQdZUpaNflvFFMBQTgNOaIL\nXmchTVcRt7V5zvbyVQVemFypTlZk7mwbobro/6cB3cPltvdg+1Qe3uEwkIoJr9y3\nQGftm74lV5TOsc0RNJvFQXuzF6WwWCfLWLtuJd9w9IR5tmk+0p6/xMDRPxpFTJZZ\nWni3fJPTUlBjN6QF1ZqtZMpKOHBF9d2ASv7fNBFVWsjag7Sn873pfb/x6djZuMlY\ncbJclFW9tEseqDWRSQ97pwsqYK9hqq7MmQTy1LxogTA0NTMuKMP17QGBC0EDwh7V\nBNIrhKiQr9kSQ9+VPKjxhjtKeyPtLsKmiRzy8wQ9+04u6xUKutSUCq7Uc254/M40\n7Vz9eEch7XWonWztKEQK2mKGaCEqz8+5YJbEjngW/zhMEuL4F72G0O/0l54kxRop\n/fUz/SFWIM0fOXhZwkJXk0XE5KthxEOfU7fDluVd0LH6DkIXB2uHBJVokYNCVjLB\nyqzMMFjeI6jC\n — — -END ENCRYPTED PRIVATE KEY — — -’

b’ — — -BEGIN PUBLIC KEY — — -\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCHDWiZvQR4nTUGiVvMjwwcyDhn\nREbiCpN62RMelmAQydaj44yUiUtGuZDhy9+TfDpUMxYuu//M+349bzVD/V6c1uT4\nnjHGXIZvTxItpb5OsN1coZ5/AnuRwx5tiVJPKY83GwJ0FpHu3xotJtQ3iiE4M6UU\nw/4U/3a/um6LFaONqwIDAQAB\n — — -END PUBLIC KEY — — -’

Process finished with exit code 0

--

--

NUR ARIF

Backend | Data Scraping | Content Writer | Python Programming | Passionate Cyber Security