리액트 네이티브에서 cryptojs 사용하기
plan text, clear text : 원래 값
encrypt, cipher text : 암호화
decrypt : 복호화
복호화는 암호화의 역과정. (즉 암호화를 풀어서 plan text로 읽히게 해주는 것)
설치:
npm react-native-crypto-js기본 사용방법은 아래와 같다. :
var encrypted = CryptoJS.AES.encrypt("메세지", "비밀 암호");
var decrypted = CryptoJS.AES.decrypt(encrypted, "비밀 암호");복호화는 과정이 하나 더 추가된다. :
let bytes = CryptoJS.AES.decrypt(ciphertext, '어쩌구');
let originaltext = bytes.toString(CryptoJS.enc.Utf8);실무에서는 특정 데이터를 암호화하여 로컬 스토리지에 저장할 것이다. :
const handleSubmit = async () => {
    const ciphertext = CryptoJS.AES.encrypt(JSON.stringify(receivingInsurance), BANK_KEY).toString();
    await AsyncStorage.setItem('@Bank', ciphertext);
}'coding > react native' 카테고리의 다른 글
| [React Native] IOS, Android facebook ATT SDK 설정하기 (0) | 2021.09.08 | 
|---|---|
| [React Native] Gradle build와 task (0) | 2021.09.07 | 
| [React Native] jdk8 build error (0) | 2021.09.03 | 
| [React Native] The minCompileSdk (31) specified in a... 빌드 에러 (0) | 2021.09.03 | 
| [React Native] 로컬저장소의 데이터를 받아서 암호화하기 (0) | 2021.04.15 | 
 
														
													
댓글