Quiero hacer una aplicación que solo genere un par de claves PGP y lo muestre en aquellos con useState pero no entendí nada en la documentación https://github.com/jerson/react-native-fast-openpgp#readme :/ alguien me puede ayudar ?
Solo generar, cifrar/descifrar sería un proyecto para más adelante, soy nuevo en React Native y no quiero complicarlo demasiado.
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', }, });
Usé la biblioteca openpgp para la reacción normal, pero con la reacción nativa no funciona, todo lo que tenía que hacer era esto:
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 ... ' }