Files
react-native-securerandom/windows/RNSecureRandom/RNSecureRandomModule.cs
T

49 lines
1.2 KiB
C#
Raw Normal View History

2017-10-11 17:27:00 +01:00
using ReactNative.Bridge;
using System;
using System.Collections.Generic;
using Windows.ApplicationModel.Core;
using Windows.UI.Core;
2017-10-11 19:33:26 +01:00
namespace Net.Rhogan.RNSecureRandom
2017-10-11 17:27:00 +01:00
{
/// <summary>
/// A module that allows JS to share data.
/// </summary>
2017-10-11 19:33:26 +01:00
class RNSecureRandomModule : NativeModuleBase
2017-10-11 17:27:00 +01:00
{
/// <summary>
2017-10-11 19:33:26 +01:00
/// Instantiates the <see cref="RNSecureRandomModule"/>.
2017-10-11 17:27:00 +01:00
/// </summary>
2017-10-11 19:33:26 +01:00
internal RNSecureRandomModule()
2017-10-11 17:27:00 +01:00
{
}
/// <summary>
/// The name of the native module.
/// </summary>
public override string Name
{
get
{
2017-10-11 19:33:26 +01:00
return "RNSecureRandom";
2017-10-11 17:27:00 +01:00
}
}
2018-09-16 16:23:16 +01:00
[ReactMethod]
public void generateSecureRandomAsBase64(int numberOfBytes, IPromise promise)
{
try
{
RandomNumberGenerator csprng = RandomNumberGenerator.Create();
byte[] rawByteArray = new byte[numberOfBytes];
csprng.GetBytes(rawByteArray);
promise.Resolve(Convert.ToBase64String(rawByteArray));
} catch (Exception ex)
{
promise.Reject(ex);
}
}
2017-10-11 17:27:00 +01:00
}
}