Encrypted messaging app
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
989 B

import 'dart:convert';
import 'package:Envelope/utils/encryption/crypto_utils.dart';
import 'package:flutter/services.dart';
import 'package:pointycastle/impl.dart';
class DeviceToken {
String id;
String userId;
String token;
String type;
DeviceToken({
required this.id,
required this.userId,
required this.token,
required this.type,
});
factory DeviceToken.fromJson(Map<String, dynamic> json, String userId, RSAPrivateKey privKey) {
Uint8List token = CryptoUtils.rsaDecrypt(
base64.decode(json['token']),
privKey,
);
Uint8List type = CryptoUtils.rsaDecrypt(
base64.decode(json['device_type']),
privKey,
);
return DeviceToken(
id: json['id'],
userId: userId,
token: String.fromCharCodes(token),
type: String.fromCharCodes(type),
);
}
Map<String, dynamic> toMap() {
return {
'id': id,
'user_id': userId,
'token': token,
'type': type,
};
}
}