简体   繁体   English

我想在本机应用程序中为给定的视频生成哈希

[英]I want to generate a hash for a given video, in a react native app

I have a video file which has been recorded from the React-native App .我有一个从React-native App录制的video文件。 Now I want to generate a digital signature, or a hash for this video file, and associate it to the blockchain.现在我想为这个video文件生成一个数字签名或哈希值,并将其关联到区块链。 Is there any way I can create a hash for the video file in the React-native App ?有什么方法可以为React-native Appvideo文件创建哈希?

You can use rnfs to hash files directly from storage.您可以使用rnfs直接从存储中散列文件。

You also can use a small package i wrote, react-native-hash , to hash directly from a URL, File or strings, how ever, it only works on Android for now.您也可以使用我编写的一个小包react-native-hash直接从 URL、文件或字符串进行哈希处理,但是,它目前仅适用于 Android。

You can use react-native-fetch-blob and js-sha3 module你可以使用react-native-fetch-blobjs-sha3模块

After encoding your video file to base64 , you can encrypt the base64 value using the hash module.将视频文件编码为base64 ,您可以使用hash模块加密base64值。

import RNFetchBlob from 'react-native-fetch-blob'
sha3_256 = require('js-sha3').sha3_256;
...

let data = ''
let hashdata = '';
RNFetchBlob.fs.readStream(
    // file path
    PATH_TO_THE_FILE,
    // encoding, should be one of `base64`, `utf8`, `ascii`
    'base64',
    // (optional) buffer size, default to 4096 (4095 for BASE64 encoded data)
    // when reading file in BASE64 encoding, buffer size must be multiples of 3.
    4095)
.then((ifstream) => {
    ifstream.open()
    ifstream.onData((chunk) => {
      // when encoding is `ascii`, chunk will be an array contains numbers
      // otherwise it will be a string
      data += chunk
    })
    ifstream.onError((err) => {
      console.log('oops', err)
    })
    ifstream.onEnd(() => {  
     hashdata = sha3_256(data); // Convert Data to Hash Value
    })
})

If use Expo如果使用世博会

import * as DocumentPicker from 'expo-document-picker';
import * as FileSystem from 'expo-file-system';
sha3_256 = require('js-sha3').sha3_256;
const response: IDocumentPickerResponse = await DocumentPicker.getDocumentAsync({
    copyToCacheDirectory: false,
    type: '*/*',
});
const file: string = await FileSystem.readAsStringAsync(
    response.uri,
    {
        encoding: FileSystem.EncodingTypes.Base64,
    });
const hashdata = sha3_256(file); // Convert Data to Hash Value

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我在我的 React Native 应用程序中使用 react-native-camera 进行视频录制。 我想用它显示计时器。 我是 React Native 的新手 - I am using react-native-camera for video recording in my React Native App. I want to show timer with it. I am new to React Native React Native:我希望应用程序在有人登录后导航到“主页” - React Native: I want the app to navigate to “Home” after someone signed in 我想在我的 React 本机应用程序中实现 Toast - I want to implement Toast into my react native app 如何在React Native应用程序中嵌入私有vimeo视频? - How can I embed a private vimeo video in a React Native app? React Native 为视频 url 生成缩略图 - React Native generate thumbnail for video url 当我想运行 debugger-ui react-native-debbugger 时,react-native 应用程序崩溃 - react-native app crashes while I want to run debugger-ui react-native-debbugger 如何实现反应原生 otp 检索器并为应用程序生成 hash 密钥 - How to Implement react native otp retriever and generate hash key for application 如何在 React Native 中生成 Android 应用程序包? - How to generate Android app bundle in React Native? 如何在 React Native 中生成 iOS 应用程序包 - How to generate iOS app bundle in React Native 反应本机生成签名的APK-:app:transformClassesWithJarMergingForRelease - React Native Generate Signed APK - :app:transformClassesWithJarMergingForRelease
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM