I want to make a App that just generates a PGP Keypair and Displays it in those with useState but i didn't unterstand anything on the Documentation https://github.com/jerson/react-native-fast-openpgp#readme :/ can someone help me ?
Just Generating, Encrypt/Decrypt would be a Project for later, Iam new to React Native and dont want to make it too complicated.
import { StatusBar } from 'expo-status-bar';
import { useState } from 'react';
import { StyleSheet, Text, View, Button } from 'react-native';
export default function App() {
const [MyPublicKey,setMyPublicKey] = useState('No key yet');
const [MyPrivateKey,setMyPrivateKey] = useState('No key yet');
const [ButtonText,setButtonText] = useState('Generate Keypair');
const GenerateKeypair = ()=>{
// This is an Example, Here Should be the Function from the Library
setMyPublicKey('-----BEGIN PGP PUBLIC KEY BLOCK-----')
setMyPrivateKey('-----BEGIN PGP Private KEY BLOCK-----')
setButtonText('renew')
}
return (
<View style={styles.container}>
<Text>{MyPublicKey}
</Text>
<Text>
{MyPrivateKey}
</Text>
<Button onPress={GenerateKeypair} title={ButtonText}/>
<StatusBar style="auto" />
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'space-evenly',
},
});
I used openpgp library for normal react but with react native it doesnt work
all i had to do is this :
const [MyPrivateKey,setMyPrivateKey] = useState(''); const [MyPublicKey,setMyPublicKey] = useState(''); const [MyRevocation,setMyRevocation] = useState(''); const GenerateKeypair = async () => { const { privateKey, publicKey, revocationCertificate } = await generateKey({ type: 'ecc', // Type of the key, defaults to ECC curve: 'curve25519', // ECC curve name, defaults to curve25519 userIDs: [{ name: 'Jon Smith', email: 'jon@example.com' }], // you can pass multiple user IDs passphrase: 'super long and hard to guess secret', // protects the private key format: 'armored' // output key format, defaults to 'armored' (other options: 'binary' or 'object') }); setMyPrivateKey(privateKey); // '-----BEGIN PGP PRIVATE KEY BLOCK ... ' setMyPublicKey(publicKey); // '-----BEGIN PGP PUBLIC KEY BLOCK ... ' setMyRevocation(revocationCertificate); // '-----BEGIN PGP PUBLIC KEY BLOCK ... ' }