![](/img/trans.png)
[英]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
[英]I want to generate a hash for a given video, in a react native app
我有一个从React-native App
录制的video
文件。 现在我想为这个video
文件生成一个数字签名或哈希值,并将其关联到区块链。 有什么方法可以为React-native App
的video
文件创建哈希?
您可以使用rnfs
直接从存储中散列文件。
您也可以使用我编写的一个小包react-native-hash直接从 URL、文件或字符串进行哈希处理,但是,它目前仅适用于 Android。
你可以使用react-native-fetch-blob
和js-sha3
模块
将视频文件编码为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
})
})
如果使用世博会
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.