[英]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 App
的video
文件创建哈希?
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-blob
和js-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.