【问题标题】:How to Encrypt and decrypt a captured images in react native?如何在本机反应中加密和解密捕获的图像?
【发布时间】:2019-02-25 09:39:49
【问题描述】:

我是 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>
    );
  }
}

【问题讨论】:

    标签: react-native encryption


    【解决方案1】:

    我已经使用 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
    

    }

    【讨论】:

      猜你喜欢
      • 2021-12-09
      • 2019-09-26
      • 2015-07-05
      • 2012-05-24
      • 2019-03-12
      • 1970-01-01
      • 2021-06-15
      • 1970-01-01
      • 2022-06-14
      相关资源
      最近更新 更多