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

  1. import 'dart:convert';
  2. import 'package:Envelope/utils/encryption/crypto_utils.dart';
  3. import 'package:flutter/services.dart';
  4. import 'package:pointycastle/impl.dart';
  5. class DeviceToken {
  6. String id;
  7. String userId;
  8. String token;
  9. String type;
  10. DeviceToken({
  11. required this.id,
  12. required this.userId,
  13. required this.token,
  14. required this.type,
  15. });
  16. factory DeviceToken.fromJson(Map<String, dynamic> json, String userId, RSAPrivateKey privKey) {
  17. Uint8List token = CryptoUtils.rsaDecrypt(
  18. base64.decode(json['token']),
  19. privKey,
  20. );
  21. Uint8List type = CryptoUtils.rsaDecrypt(
  22. base64.decode(json['device_type']),
  23. privKey,
  24. );
  25. return DeviceToken(
  26. id: json['id'],
  27. userId: userId,
  28. token: String.fromCharCodes(token),
  29. type: String.fromCharCodes(type),
  30. );
  31. }
  32. Map<String, dynamic> toMap() {
  33. return {
  34. 'id': id,
  35. 'user_id': userId,
  36. 'token': token,
  37. 'type': type,
  38. };
  39. }
  40. }