Add comments and typehelper
This commit is contained in:
parent
d382ec1a7b
commit
f7d88e47ea
@ -11,7 +11,11 @@ class NativeCrypto {
|
||||
static const MethodChannel _channel =
|
||||
const MethodChannel('native.crypto.helper');
|
||||
|
||||
Future<Uint8List> sumKeygen() async {
|
||||
/// Generates AES key.
|
||||
///
|
||||
/// Size of **256 bits** by design.
|
||||
/// And returns `Uint8List`.
|
||||
Future<Uint8List> symKeygen() async {
|
||||
final Uint8List aesKey = await _channel.invokeMethod('symKeygen');
|
||||
|
||||
log('AES Key Length: ${aesKey.length}', name: _tag);
|
||||
@ -20,6 +24,11 @@ class NativeCrypto {
|
||||
return aesKey;
|
||||
}
|
||||
|
||||
/// Encrypts passed data with a given AES key.
|
||||
///
|
||||
/// Generates a random **IV**. Returns a list
|
||||
/// of `Uint8List` with encrypted cipher as first
|
||||
/// and IV as second member.
|
||||
Future<List<Uint8List>> symEncrypt(
|
||||
Uint8List payloadbytes, Uint8List aesKey) async {
|
||||
final List<Uint8List> encryptedPayload =
|
||||
@ -37,6 +46,10 @@ class NativeCrypto {
|
||||
return encryptedPayload;
|
||||
}
|
||||
|
||||
/// Decrypts a passed payload with a given AES key.
|
||||
///
|
||||
/// The payload must be a list of `Uint8List`
|
||||
/// with encrypted cipher as first and IV as second member.
|
||||
Future<Uint8List> symDecrypt(
|
||||
List<Uint8List> payloadbytes, Uint8List aesKey) async {
|
||||
final Uint8List decryptedPayload =
|
||||
@ -48,3 +61,18 @@ class NativeCrypto {
|
||||
return decryptedPayload;
|
||||
}
|
||||
}
|
||||
|
||||
class TypeHelper {
|
||||
/// Returns bytes `Uint8List` from a `String`.
|
||||
Uint8List stringToBytes(String source) {
|
||||
var list = source.codeUnits;
|
||||
var bytes = Uint8List.fromList(list);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
/// Returns a `String` from bytes `Uint8List`.
|
||||
String bytesToString(Uint8List bytes) {
|
||||
var string = String.fromCharCodes(bytes);
|
||||
return string;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user