Encrypting passwords with crypto-js (SHA256)
At work, the back end asked me to encrypt the password before sending it when creating a member. When I asked my senior, I heard that our company hashes the password with crypto-js before passing it on, so I came home and practiced it once more.
First, run the code below.
bash
npm install crypto-jsbash
npm install --save @types/crypto-jsNext, the practice code is below.
jsx
import React, { useState } from "react";
import { SHA256 } from "crypto-js";
export default function HashPwd() {
const [pwd, setPwd] = useState("");
const password = pwd;
const hashedPassword = SHA256(password).toString();
const handleSubmit = () => {
console.log(hashedPassword);
};
return (
<>
<input type="password" onChange={(e) => setPwd(e.target.value)} />
<button type="submit" onClick={() => handleSubmit()}>
제출
</button>
</>
);
}- At work I installed it with yarn, but at home it was a React project made with Vite, so there was a JavaScript version difference. I used an import statement instead of a require statement.

I learned one more thing today!
- #crypto-js
- #import
- #require
- #SHA256
- #Encryption