Encryption in Typescript
In this blog, I have used the crypto library to
Generate random numbers
Generate Hash
Encrypt and decrypt data
I have coded for encrypting data using the 'aes-256-cbc' algorithm. In real life, you must encrypt sensitive information like credit card information, secret keys, etc. before storing it in the database. This will prevent the misuse of this sensitive information if the data gets leaked. You will also need a way to decrypt this information when required. In this blog/video, I have written a basic code in typescript to encrypt and decrypt information.
In this video, I have coded using the crypto library in Node.js to encrypt some random text. I dive into crypto in JavaScript and in TypeScript to generate cryptographically safe random numbers, create strong hashes, and securely encrypt sensitive data such as credit card numbers and CVVs. You'll learn how to store this encrypted data in a database and decrypt it when needed.
Discover the use of crypto in a Node.js project, including how to use Node crypto to encrypt and decrypt tokens. Whether you're working on securing emails, sensitive documents, or any kind of private information, this tutorial will guide you through the steps of encryption and decryption using AES and other algorithms.
By the end of this, you’ll know how to encrypt emails, protect your data from hacking, and securely handle sensitive information in your Node.js applications. Plus, I cover practical examples like how to encrypt and decrypt text in JavaScript, and Typescript, and explore topics like initialization vectors, cipher modes, and more.
Generate random numbers
import * as crypto from 'crypto';
// async
crypto.randomBytes(16, (err, buf) => {
console.log(buf.toString('hex'));
});
// sync
let iv1 = crypto.randomBytes(16); // initialization vector
console.log(iv1.toString('hex'));Generate hash
let hash = crypto.createHash('md5-sha1').update('code with gd').digest('hex');
console.log(hash);
console.log(crypto.getHashes());Encrypt data
let iv = crypto.randomBytes(16);
let credit_card = '901445912340985';
let cvv = '725';
// console.log(crypto.getCiphers());
let secret_key = 'n8XIkjtyxtJk80mwstUTEHLPf4gOfLQI'; // store in //configs
let cipher = crypto.createCipheriv('aes-256-cbc', secret_key, iv);
let encrypted_credit_card = cipher.update(credit_card, 'utf-8', 'hex');
encrypted_credit_card += cipher.final('hex');
let cipherCvv = crypto.createCipheriv('aes-256-cbc', secret_key, iv);
let encrypted_cvv = cipherCvv.update(cvv, 'utf-8', 'hex');
encrypted_cvv += cipherCvv.final('hex');
console.log('Encrypted Credit Card Number: ', encrypted_credit_card);
console.log('Encrypted Credit Card CVV: ', encrypted_cvv);
console.log('--------------');Decrypt Data
// Decipher
let decipher = crypto.createDecipheriv('aes-256-cbc', secret_key, iv);
let decrypted_credit_card = decipher.update(
encrypted_credit_card,
'hex',
'utf-8'
);
decrypted_credit_card += decipher.final('utf8');
let decipherCvv = crypto.createDecipheriv('aes-256-cbc', secret_key, iv);
let decrypted_cvv = decipherCvv.update(encrypted_cvv, 'hex', 'utf-8');
decrypted_cvv += decipherCvv.final('utf8');
console.log('Deciphered Credit Card Number: ', decrypted_credit_card);
console.log('Deciphered Credit Card CVV: ', decrypted_cvv);





_edited.png)







































































soi cau mb mình vào xem đúng kiểu đọc lướt thôi, không tính chuyện chốt số hay đúng sai gì cả. Trang này chia nội dung thành từng khối nhìn khá gọn, kéo xuống là thấy mạch bài chạy theo tiêu đề. Mình để ý mục “Soi cầu MB ngày 3 9 2026” đặt ngay ngắn, chữ rõ nên không phải đoán đang nói phần nào. Đoạn dự đoán XSMB hôm nay viết theo kiểu ngắn gọn, có mấy cụm như “chạm đầu đuôi” hay “bạch thủ” được ngắt dòng nên đọc đỡ mỏi. Nói chung giao diện không cầu kỳ, nhưng dễ theo dõi khi chỉ muốn xem nhanh. Cuối trang vẫn giữ heading lớn cho phần “Dự đoán…
I enjoyed reading this post because the information feels natural and clear. I explored Slope 3 and liked the challenging routes, quick movement, obstacle avoidance, and simple controls. The game creates an engaging experience by testing timing, focus, and player skills.
من المميزات المهمة في التطبيق دعمه لجودات عرض متعددة. يمكن للمستخدم اختيار الجودة المناسبة حسب سرعة الإنترنت المتوفرة لديه. وهذا يساعد على جعل المشاهدة أكثر استقرارًا. كما يساهم في تقليل التوقفات أثناء التشغيل.
https://alostoratv.app/alostora-tv-ios/
Great article! I completely agree that smart furniture choices can transform a living space. A Sofa Cum Bed 3-Seater is a perfect example of furniture that offers both comfort and functionality. It works well as a stylish sofa and quickly converts into a bed when needed. Definitely a practical solution for modern homes.
Dordle is a completely free online game with an appealing puzzle theme suitable for all audiences. Participants will be charged with deducing two words while using two boards.