Posts

Showing posts with the label Cryptography

Go Language - RSA Encryption And Decryption Example

Image
The RSA algorithm (Rivest-Shamir-Adleman) is a cryptographic algorithm that is used for specific security services or purposes, which enables public-key encryption and is widely used to secure sensitive data, particularly when it is being sent over an insecure network such as the HTTP. A public key is shared publicly, while a private key is secret and must not be shared with anyone. The following illustration highlights how asymmetric cryptography works: Example 1: RSA Encryption and Decryption with OAEP, package main //Required imports for Encryption & Decryption import ( "crypto/rand" "crypto/rsa" "crypto/sha512" "encoding/base64" "fmt" ) func main() { //3072 is the number of bits for RSA bitSize := 3072 //Generate RSA keys privateKey, err := rsa. GenerateKey(rand.Reader, bitSize) if err != nil { panic(err) } publicKey := privateKey.PublicKey //Your secret te

Python RSA Encryption And Decryption Example

Image
The RSA algorithm (Rivest-Shamir-Adleman) is a cryptographic algorithm that is used for specific security services or purposes, which enables public-key encryption and is widely used to secure sensitive data, particularly when it is being sent over an insecure network such as the HTTP. A public key is shared publicly, while a private key is secret and must not be shared with anyone. The following illustration highlights how asymmetric cryptography works: Example , RSA Encryption and Decryption with RSA-OAEP Padding, from Crypto.PublicKey import RSA from Crypto.Cipher import PKCS1_OAEP import base64 # 2048 is the number of bits for RSA keys = RSA.generate( 2048 ) publicKey = keys.publickey() publicKeyPEM = publicKey.exportKey() print( "\n" ,publicKeyPEM.decode( 'ascii' )) privateKeyPEM = keys.exportKey() print( "\n" ,privateKeyPEM.decode( 'ascii' )) # Your secret text secretMessage = 'This is your secret' #encrypt the message with the RS

Node.js - RSA Encryption And Decryption Example

Image
The RSA algorithm (Rivest-Shamir-Adleman) is a cryptographic algorithm that is used for specific security services or purposes, which enables public-key encryption and is widely used to secure sensitive data, particularly when it is being sent over an insecure network such as the HTTP. A public key is shared publicly, while a private key is secret and must not be shared with anyone. The following illustration highlights how asymmetric cryptography works: Program to demonstrate RSA encryption and decryption in Node.js, const crypto = require( "crypto" ) // Generating RSA key pairs(public and private key) const { publicKey, privateKey } = crypto.generateKeyPairSync( "rsa" , { // The length of our RSA keys is 3072 bits modulusLength: 3072 , }) //print RSA public key and private key console.log( publicKey.export({ type: "pkcs1" , format: "pem" , }), privateKey.export({ type: "pkcs1" , fo

Kotlin- Blowfish Encryption and decryption Example

Blowfish is a symmetric-key block cipher, designed in 1993 by Bruce Schneier. Symmetric encryption uses a single encryption key to both encrypt and decrypt data. The sensitive data and the symmetric encryption key are utilized within the encryption algorithm to turn the sensitive data into ciphertext Blowfish provides a good encryption rate in software. However, the Advanced Encryption Standard (AES) now receives more attention, and Schneier recommends Twofish for modern applications. Example: import java.io.UnsupportedEncodingException import java.nio.charset.Charset import java.security.InvalidKeyException import java.security.NoSuchAlgorithmException import java.util.* import javax.crypto.BadPaddingException import javax.crypto.Cipher import javax.crypto.IllegalBlockSizeException import javax.crypto.NoSuchPaddingException import javax.crypto.spec.SecretKeySpec /** * This program demonstrates how to * encrypt/decrypt input using the Blowfish * Cipher with the Java Crypto

Kotlin - RSA Encryption and Decryption example

Image
The RSA algorithm (Rivest-Shamir-Adleman) is a cryptographic algorithm that is used for specific security services or purposes, which enables public-key encryption and is widely used to secure sensitive data, particularly when it is being sent over an insecure network such as the HTTP. A public key is shared publicly, while a private key is secret and must not be shared with anyone. The following illustration highlights how asymmetric cryptography works: Example 1: The Cipher Type: RSA/ECB/PKCS1Padding import java.security.spec.PKCS8EncodedKeySpec import javax.crypto.Cipher import java.security.spec.X509EncodedKeySpec import java.io.IOException import java.security.* import java.util.* /* * RSA Key Size: 1024 * Cipher Type: RSA/ECB/PKCS1Padding */ class RSAKotlinDemo1 { var privateKey: PrivateKey var publicKey: PublicKey companion object { // convert String publickey to Key object @Throws (GeneralSecurityException:: class , IOException:: class