Skip to content

Commit

Permalink
chore: pem header 수정 및 example testing
Browse files Browse the repository at this point in the history
  • Loading branch information
ko-devHong committed May 2, 2024
1 parent 3297990 commit e7387e3
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
4 changes: 2 additions & 2 deletions android/src/main/java/com/cryptorsa/CryptoRsa.kt
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,8 @@ class CryptoRsa(originReactContext: ReactApplicationContext, originKeySize:Int?)
private const val KEY_STORE_TYPE = "AndroidKeyStore"
private const val PREFERENCE_NAME = "ReactNativeRsaPreferences"
private const val PRIVATE_KEY_ALIAS = "ReactNativeRsaPrivateKey"
private const val PUBLIC_HEADER = "RSA PUBLIC KEY"
private const val PRIVATE_HEADER = "RSA PRIVATE KEY"
private const val PUBLIC_HEADER = "PUBLIC KEY"
private const val PRIVATE_HEADER = "PRIVATE KEY"
private const val TAG = "ReactNativeRsa"
@RequiresApi(Build.VERSION_CODES.M)
private const val RSA_ALGORITHM = KeyProperties.KEY_ALGORITHM_RSA;
Expand Down
37 changes: 32 additions & 5 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,54 @@
import * as React from 'react';
import { useEffect } from 'react';
import { useEffect, useState } from 'react';

import { StyleSheet, Text, View } from 'react-native';
import { Pressable, StyleSheet, Text, TextInput, View } from 'react-native';
import RNCryptoRsa from '@ko-developerhong/react-native-crypto-rsa';

export default function App() {
const [result, setResult] = React.useState<string | undefined>();
const [result, setResult] = useState<string | undefined>();
const [base64String, setBase64String] = useState('');
const [publicString, setPublicString] = useState('');

useEffect(() => {
(async () => {
const { publicKey } = await RNCryptoRsa.init();
setPublicString(publicKey);
const encryptBase64String = await RNCryptoRsa.encrypt(
'hello world',
publicKey
);
const originString = await RNCryptoRsa.decrypt(encryptBase64String);
setResult(originString);
console.log('@encryptBase64String : ', encryptBase64String);
})();
}, []);

const decryptString = async () => {
console.log('base64String : ', base64String);
const originString = await RNCryptoRsa.decrypt(base64String);
setResult(originString);
};

return (
<View style={styles.container}>
<TextInput
style={{
marginTop: 30,
width: '90%',
marginHorizontal: 20,
borderWidth: 1,
height: 200,
borderColor: 'gray',
}}
onChangeText={setBase64String}
value={base64String}
/>
<Text>publicKey : {publicString} </Text>
<Text>Result: {result}</Text>
<Pressable
style={{ backgroundColor: 'skyblue', padding: 10, marginTop: 20 }}
onPress={decryptString}
>
<Text>Press decrypt</Text>
</Pressable>
</View>
);
}
Expand Down

0 comments on commit e7387e3

Please sign in to comment.