UNPKG

@react-native-ohos/react-native-get-random-values

Version:

This project is based on [react-native-get-random-values](https://github.com/LinusU/react-native-get-random-values)

40 lines (27 loc) 1.05 kB
/* * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved * Use of this source code is governed by a MIT license that can be * found in the LICENSE file. */ import { TurboModule } from '@rnoh/react-native-openharmony/ts'; import { TM } from './generated/ts'; import window from '@ohos.window'; import { util } from '@kit.ArkTS'; export class RNGetRandomValuesTurboModule extends TurboModule implements TM.GetRandomValuesNativeModule.Spec { windowClass:window.Window| undefined = undefined; isKeepScreenOn: boolean = true; unisKeepScreenOn: boolean = false; constructor(ctx) { super(ctx); } getRandomBase64(byteLength:number){ const randomBytes = new Uint8Array(byteLength) for(var i = 0 ; i<byteLength;i++){ randomBytes[i] = Math.floor(Math.random()*256) } const that = new util.Base64Helper() const base64String = that.encodeToStringSync(randomBytes); //将随机字节数组转换为Base64编码的字符串 return base64String } }