Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使用base64加密在react native中加密密码,我是react native的新手_Javascript_React Native_Base64 - Fatal编程技术网

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

Javascript 如何使用base64加密在react native中加密密码,我是react native的新手,javascript,react-native,base64,Javascript,React Native,Base64,这是名为LoginBg的文件的代码,我必须在其中加密密码。如何从password的输入字段中获取文本并使用base64编码对其进行加密 export default class LoginBg extends React.Component { constructor(props) { super(props); this.state ={ username:"", password:"",

这是名为
LoginBg
的文件的代码,我必须在其中加密密码。如何从password的输入字段中获取文本并使用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>
    );
    }
   }
导出默认类LoginBg扩展React.Component{
建造师(道具){
超级(道具);
这个州={
用户名:“”,
密码:“”,
}
}
_女佣(){
console.log(this.state.username);
console.log(this.state.password);
}
render(){
返回(
-登录页面-
this.setState({username:text})placeholder=“Email”placeholder textcolor=“#eaf4fc”style={styles.input}/>
this.setState({password:text})placeholder=“password”placeholder textcolor=“#eaf4fc”style={styles.input}/>
这是.\u handlePress()}>登录
登记
);
}
}
在这种情况下,您可以使用第三方模块

安装

$npm安装--保存js-base64

用法

import { Base64 } from 'js-base64';

Base64.encode('dankogai');  // ZGFua29nYWk=

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


旁注:即使在服务器端加密密码的使用也是有限的,通常只有当您需要它与其他系统交互时才使用,因此您需要在存储密码之前对其进行加密,并在使用密码之前对其进行解密。如果解密密钥也存储在相同的环境中,则不会增加很多安全性。对于登录到您系统的用户,密码应该被散列,这是一个与加密不同的单向函数。

重要的是要理解
base64
不是加密,因此它不会为密码之类的东西提供任何级别的安全性。为什么要使用外部库?浏览器对atob和btoa方法的支持相当好。他正在开发一个移动应用程序。根据我的代码,我如何才能准确地使用你给定的代码?