-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #494 from atsign-foundation/pass_optional_key_params
feat: at_chops - add optional public key/private key to asymmetric encryption, major version release
- Loading branch information
Showing
16 changed files
with
183 additions
and
329 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 0 additions & 32 deletions
32
packages/at_chops/lib/src/algorithm/default_encryption_algo.dart
This file was deleted.
Oops, something went wrong.
45 changes: 45 additions & 0 deletions
45
packages/at_chops/lib/src/algorithm/rsa_encryption_algo.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import 'dart:typed_data'; | ||
|
||
import 'package:at_chops/src/algorithm/at_algorithm.dart'; | ||
import 'package:at_chops/src/key/at_private_key.dart'; | ||
import 'package:at_chops/src/key/at_public_key.dart'; | ||
import 'package:at_chops/src/key/impl/at_encryption_key_pair.dart'; | ||
import 'package:at_commons/at_commons.dart'; | ||
import 'package:crypton/crypton.dart'; | ||
|
||
class RsaEncryptionAlgo implements ASymmetricEncryptionAlgorithm { | ||
AtEncryptionKeyPair? _encryptionKeypair; | ||
RsaEncryptionAlgo.fromKeyPair(this._encryptionKeypair); | ||
RsaEncryptionAlgo(); | ||
@override | ||
Uint8List encrypt(Uint8List plainData) { | ||
if ((_encryptionKeypair == null || | ||
_encryptionKeypair!.atPublicKey.publicKey.isEmpty) && | ||
(atPublicKey == null || atPublicKey!.publicKey.isEmpty)) { | ||
throw AtEncryptionException('EncryptionKeypair/public key not set'); | ||
} | ||
var publicKeyString = atPublicKey?.publicKey; | ||
publicKeyString ??= _encryptionKeypair!.atPublicKey.publicKey; | ||
final rsaPublicKey = RSAPublicKey.fromString(publicKeyString); | ||
return rsaPublicKey.encryptData(plainData); | ||
} | ||
|
||
@override | ||
Uint8List decrypt(Uint8List encryptedData) { | ||
if ((_encryptionKeypair == null || | ||
_encryptionKeypair!.atPrivateKey.privateKey.isEmpty) && | ||
(atPrivateKey == null || atPrivateKey!.privateKey.isEmpty)) { | ||
throw AtDecryptionException('EncryptionKeypair/public key not set'); | ||
} | ||
var privateKeyString = atPrivateKey?.privateKey; | ||
privateKeyString ??= _encryptionKeypair!.atPrivateKey.privateKey; | ||
final rsaPrivateKey = RSAPrivateKey.fromString(privateKeyString); | ||
return rsaPrivateKey.decryptData(encryptedData); | ||
} | ||
|
||
@override | ||
AtPrivateKey? atPrivateKey; | ||
|
||
@override | ||
AtPublicKey? atPublicKey; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.