Posts

Java - DES Encryption and Decryption example

DES (Data Encryption Standard) algorithm is the most commonly used encryption  symmetric-key  algorithm in the world. For a long time, "cipher generation" was synonymous with DES in many people's minds. Although the Electronic Frontier Foundation recently called, it built a 220,000 machine to try to crack DES encrypted data. DES and its variant "triple data encryption algorithm" will still be widely used in government and banking. AES became the replacement for DES).   DES processes bits or binary numbers. We know that every four bits make up a hexadecimal number. DES encrypts a set of 64-bit information, which is represented by 16 hexadecimal numbers. DES also uses 64-bit long ciphers to provide encryption. However, every 8 bits in the key are ignored, resulting in a correct key length of 56 bits in DES. However, in any case, one 64-bit block is an eternal DES organization. Java DES Encryption and Decryption   import javax.crypto.Cipher; import javax.crypto.K

Java - RSA Encryption and Decryption example - Asymmetric cryptography

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.io.IOException; import java.security.GeneralSecurityException; import java.security.Key; import java.security.KeyFactory; import java.security.KeyPair; import java.security.KeyPairGenerator; import java.security.NoSuchAlgorithmException; import java.security.PrivateKey; import java.security.PublicKey; import java.security.spec.PKCS8EncodedKeySpec; import java.security.spec.X509EncodedKeySpec; import java.util.Arrays; import java.util.Base64; import javax.crypto

JAVA - AES Encryption and Decryption example - Symmetric cryptography

Image
Advanced Encryption Standard which is a symmetric encryption algorithm. AES encryption is used by the U.S. to secure sensitive but unclassified material, so we can say it is secure enough. Advanced Encryption Standard(AES) is a symmetric encryption algorithm. AES is the industry standard now as it allows 128-bit, 192-bit and 256-bit encryption. Symmetric encryption is very fast as compared to asymmetric encryption and is used in systems such as database systems. The following illustration highlights how symmetric cryptography works: Example: import java.io.UnsupportedEncodingException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; import java.util.Arrays; import java.util.Base64; import javax.crypto.Cipher; import javax.crypto.KeyGenerator; import javax.crypto.spec.SecretKeySpec; public class AESDemo { private static SecretKeySpec secretKey; private static byte [] key; public static