crypto


1. Encrypting and Decrypting Data with AES-256

const crypto = require('crypto');

// Encrypting data
const encryptedData = crypto.createCipher('aes-256-cbc', 'myPassword').update('Hello World').final('hex');

// Decrypting data
const decryptedData = crypto.createDecipher('aes-256-cbc', 'myPassword').update(encryptedData, 'hex').final('utf8');

2. Hashing Data with SHA-256

const crypto = require('crypto');

const hash = crypto.createHash('sha256').update('Hello World').digest('hex');

3. Signing Data with RSA

const crypto = require('crypto');

const privateKey = crypto.createPrivateKey({
  key: fs.readFileSync('private.pem'),
  format: 'pem',
});

const signature = crypto.sign('sha256', Buffer.from('Hello World'), privateKey);

4. Verifying Signature with RSA

5. Generating a Random String

6. Generating a Secure Random Number

7. Encrypting and Decrypting Data with HMAC

8. Encrypting and Decrypting Data with Cipher IV

9. Encrypting and Decrypting Data with GCM

10. Generating a Diffie-Hellman Key Pair

11. Exchanging a Secret with Diffie-Hellman

12. Generating an RSA Key Pair

13. Encrypting Data with Public RSA Key

14. Decrypting Data with Private RSA Key

15. Generating an ECDSA Key Pair

16. Signing Data with Private ECDSA Key

17. Verifying Signature with Public ECDSA Key

18. Generating a DSA Key Pair

19. Signing Data with Private DSA Key

20. Verifying Signature with Public DSA Key

21. Generating a DH Key Pair

22. Exchanging a Secret with DH

23. Encrypting Data with AES in CBC Mode

24. Decrypting Data with AES in CBC Mode

25. Encrypting Data with AES in CFB Mode

26. Decrypting Data with AES in CFB Mode

27. Encrypting Data with AES in OFB Mode

28. Decrypting Data with AES in OFB Mode

29. Encrypting Data with AES in CTR Mode

30. Decrypting Data with AES in CTR Mode

31. Encrypting Data with Triple DES in ECB Mode

32. Decrypting Data with Triple DES in ECB Mode

33. Encrypting Data with Triple DES in CBC Mode

34. Decrypting Data with Triple DES in CBC Mode

35. Encrypting Data with Blowfish in CBC Mode

36. Decrypting Data with Blowfish in CBC Mode