我如何使用base64加密在react-native中加密密码,我是react-native的新手

-1 javascript base64 react-native

这是我的名字的代码LoginBg,我必须加密密码.如何从密码的输入字段获取文本并使用base64编码加密?

        export default class LoginBg extends React.Component {

    constructor(props) {
        super(props);
        this.state ={
            username:"",
            password:"",
        }

      }

      _handlePress() {
        console.log(this.state.username);
        console.log(this.state.password);
     }


    render(){

    return (
        <KeyboardAvoidingView behavior="position" style={styles.container}>
            <Text style={styles.heading}>- Login Page -</Text>
            <TextInput keyboardType='email-address' underlineColorAndroid='transparent'  onChangeText={(text) => this.setState({username:text})} placeholder="Email"  placeholderTextColor="#eaf4fc" style={styles.input}/>
            <TextInput secureTextEntry underlineColorAndroid='transparent' onChangeText={(text) => this.setState({password:text})} placeholder="Password" placeholderTextColor="#eaf4fc" style={styles.input}/>
            <Button onPress={() => this._handlePress()}>Login</Button>
            <Button>Register</Button>
        </KeyboardAvoidingView>
    );
    }
   }
Run Code Online (Sandbox Code Playgroud)

Seb*_*oek 15

你不应该这样做,Base64是一种编码,它不是加密!您不会以这种方式添加任何有意义的安全性.密码在服务器端加密(如果有的话,请参阅下面的注释),而不是在客户端.即使你实际上已经加密了客户端的密码并发送了它,那么基本上加密的密码就成了新的纯文本密码.如果您不清楚这一点,请在实施安全性之前再做一些研究.

附注:即使用于加密密码服务器端的用途也是有限的,通常只有当您需要它与其他系统进行交互时才进行加密,以便在存储之前对其进行加密并在使用之前进行解密.如果解密密钥也存储在同一环境中,则不会增加很多安全性.对于登录系统的自己的用户,密码应该是哈希值,而不是加密,这是一种单向函数.