forked from HackMIT-SecureQRCode/secure-qr-code-scanner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEncrypt.js
68 lines (66 loc) · 1.84 KB
/
Encrypt.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import React from 'react';
import {
AppRegistry,
Text,
TextInput,
Button,
View,
AsyncStorage,
Keyboard,
StyleSheet
} from 'react-native';
import {createEncryption} from './api';
import RSAKey from 'react-native-rsa';
import QRCode from 'react-native-qrcode-svg';
export default class Encrypt extends React.Component {
static navigationOptions = {
title: 'Encrypt',
};
constructor(props) {
super(props);
this.state = {text: '', cypher_text: ''}
this.onEncrypt = this.onEncrypt.bind(this);
}
onEncrypt() {
createEncryption("John", this.state.text, (response) => {
const encrypted_message = response.data.text
// obviously insecure, use a keychain system irl
AsyncStorage.setItem("@RSAKeyStore:private_key", response.data.key);
this.setState({cypher_text: encrypted_message});
Keyboard.dismiss();
});
}
render() {
return (
<View style={{padding: 10, justifyContent: 'center', alignItems: 'center'}}>
<TextInput
style={{height: 40}}
placeholder="Type your plaintext here"
onChangeText={(text) => this.setState({text})}
/>
<Button
onPress={this.onEncrypt}
title="Generate QR Code"
/>
{this.state.cypher_text ?
<View>
<QRCode
value={this.state.cypher_text}
size={350}
style={styles.qrcode}
/>
<Button
title="Download"
/>
</View>
: null}
</View>
)
}
}
const styles = StyleSheet.create({
qrcode: {
justifyContent: 'center',
alignItems: 'center',
}
});