Encrypt text to Sha256 format react native

 import React,{useState}from 'react';

import {Button, Pressable,TextInput, StyleSheet, Text,ScrollView, View} from 'react-native';
import {sha256} from 'react-native-sha256';

export const home = ({navigation}) => {
    const [inpText,setInpText] = useState();
    const [encText,setEncText] = useState();

    const handleConvert = () => {
        sha256(inpText).then((code)=>{
            setEncText(code)
        })
    }

  return (
      <ScrollView>
    <View style={styleSheet.homeContainer}>
      <TextInput style={styleSheet.textInput} onChangeText={(text)=>{setInpText(text)}}></TextInput>
      <Text style={styleSheet.text}>{encText}</Text>
      <Button title='Convert to Sha256' onPress={()=>{handleConvert()}}></Button>
    </View></ScrollView>
  );
};

const styleSheet = StyleSheet.create({
  homeContainer: {
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center',
  },
  textInput:{
      width:'80%',
      borderRadius:10,
      borderWidth:1,
      padding:10,
      margin:20
  }
 
 
});

Comments