我是React Native的初学者。我可以使用react-native-image-picker捕获图像,并且可以将捕获的照片上传到AWS s3。但是,我想在Android设备中对捕获的图像进行加密或散列,并且在上传之前,我需要解密它们。所拍摄的照片必须在手机内加密/散列,仅通过我的应用程序,我就需要解密它们。我该如何实现。
有两种方法,
在takePic方法中,我想先对其进行加密,然后再存储在设备中;在上载方法中,我想在上传之前对其进行解密。我用谷歌搜索。但是我没有得到任何适当的文档。
您能帮忙吗?
我的代码是
import React, { Component } from "react";
import {
Platform,
StyleSheet,
Alert,
Text,
TouchableOpacity,
View,
Picker,
Animated,
Easing,
Image
} from "react-native";
import ImagePicker from "react-native-image-picker";
import { RNS3 } from "react-native-aws3";
export default class SecondScreen extends Component<Props> {
constructor(props) {
super(props);
this.state = {
file: "",
saveImages: []
};
}
takePic() {
const options = {
quality: 1.0,
maxWidth: 50,
maxHeight: 50,
}
ImagePicker.launchCamera(options,(responce)=>{
const file = {
uri: responce.uri,
name: responce.fileName,
method: "POST",
path: responce.path,
type: responce.type,
notification: {
enabled: true
}
};
this.state.saveImages.push(file);
});
}
_upload = saveImages => {
const config = {
keyPrefix: "uploads/",
bucket: "myBukectName",
region: "us-east-2",
accessKey: "***",
secretKey: "***",
successActionStatus: 201
};
this.state.saveImages.map(image => {
RNS3.put(image, config).then(responce => {
console.log(saveImages);
});
});
//once after upload is done delete from the gallary
};
render() {
return (
<View style={styles.container}>
<View style={styles.Camera}>
<TouchableOpacity onPress={this.takePic.bind(this)}>
<Text>Take Picture</Text>
</TouchableOpacity>
</View>
<View style={styles.Send}>
<TouchableOpacity onPress={() => this._upload()}>
<Text>Send</Text>
</TouchableOpacity>
</View>
</View>
);
}
}
答案 0 :(得分:0)
我已经使用react-native-base64做到了,我正在使用python在服务器端进行解密。 (从文件中获取base64数据并进行解码。)
takePic(){
//set of other codes
const base64 = RNFS.writeFile(responce.uri, responce.data);
return base64;
//this will create the base64 image file
}