mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-27 09:06:43 +08:00
Experiment: Try to generate ECC keys in Dart
I'm stuck at how to convert them between two formats.
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:basic_utils/basic_utils.dart';
|
||||
import 'package:git_bindings/git_bindings.dart' as gb;
|
||||
import 'package:path/path.dart' as p;
|
||||
|
||||
@ -76,3 +77,22 @@ Future<SshKey?> generateSSHKeysNative({required String comment}) async {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
Future<SshKey> generateSSHEccKeys({required String comment}) async {
|
||||
print("Generating KeyPair ...");
|
||||
var stopwatch = Stopwatch()..start();
|
||||
var keyPair = CryptoUtils.generateEcKeyPair(curve: 'secp384r1');
|
||||
var publicKey = keyPair.publicKey as ECPublicKey;
|
||||
var privateKey = keyPair.privateKey as ECPrivateKey;
|
||||
print("Generating KeyPair took: ${stopwatch.elapsed}");
|
||||
|
||||
var publicPem = CryptoUtils.encodeEcPublicKeyToPem(publicKey);
|
||||
var privatePem = CryptoUtils.encodeEcPrivateKeyToPem(privateKey);
|
||||
|
||||
// FIXME: I need to learn to convert from the public key PEM format to ecdsa-sha2-nistp384
|
||||
return SshKey(
|
||||
publicKey: publicPem,
|
||||
privateKey: privatePem,
|
||||
password: "",
|
||||
);
|
||||
}
|
||||
|
@ -55,3 +55,27 @@ String privateKeyString() {
|
||||
// -> https://golang.org/src/crypto/x509/pkcs8.go
|
||||
|
||||
// Key format is PKCS8 or OpenSSH.
|
||||
|
||||
/*
|
||||
String publicKeyString(ECPublicKey publicKey, String comment) {
|
||||
var publicPem = CryptoUtils.encodeEcPublicKeyToPem(publicKey);
|
||||
|
||||
print('public PEM');
|
||||
print(publicPem);
|
||||
print('\n');
|
||||
|
||||
var publicKeyBytes = CryptoUtils.getBytesFromPEMString(publicPem);
|
||||
var data = BinaryLengthValue.encode([
|
||||
BinaryLengthValue.fromString("ecdsa-sha2-nistp384"),
|
||||
BinaryLengthValue(publicKeyBytes),
|
||||
]);
|
||||
|
||||
if (comment.isNotEmpty) {
|
||||
comment = comment.replaceAll('\r', ' ');
|
||||
comment = comment.replaceAll('\n', ' ');
|
||||
comment = ' $comment';
|
||||
}
|
||||
|
||||
return 'ecdsa-sha2-nistp384 ${base64.encode(data)}$comment';
|
||||
}
|
||||
*/
|
||||
|
23
pubspec.lock
23
pubspec.lock
@ -29,13 +29,6 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.0"
|
||||
asn1lib:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: asn1lib
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.0"
|
||||
async:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -57,6 +50,13 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.1"
|
||||
basic_utils:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: basic_utils
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.1.0"
|
||||
benchmark_harness:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
@ -246,13 +246,6 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.0.1"
|
||||
crypton:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: crypton
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.1"
|
||||
csv:
|
||||
dependency: transitive
|
||||
description:
|
||||
@ -949,7 +942,7 @@ packages:
|
||||
name: pointycastle
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.0.1"
|
||||
version: "3.1.1"
|
||||
pool:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -23,10 +23,10 @@ dependencies:
|
||||
git: https://github.com/GitJournal/icloud_documents_path.git
|
||||
auto_size_text: ^3.0.0-nullsafety.0
|
||||
badges: ^2.0.1
|
||||
basic_utils: ^3.1.0
|
||||
connectivity: ^3.0.3
|
||||
# cryptography: ^1.4.1
|
||||
# cryptography_flutter: ^1.0.0
|
||||
crypton: ^2.0.1
|
||||
dashbook: ^0.1.2
|
||||
device_info: ^2.0.0
|
||||
dots_indicator: ^2.0.0
|
||||
|
Reference in New Issue
Block a user