mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-29 18:38:36 +08:00
keygen experiment: Try to generate an ed25519 key
This commit is contained in:
@ -1,12 +1,21 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:gitjournal/ssh/rsa_key_pair.dart';
|
||||
import 'package:cryptography/cryptography.dart';
|
||||
|
||||
void main() {
|
||||
import './binary_length_value.dart';
|
||||
|
||||
void main() async {
|
||||
print("Generating new random key");
|
||||
var keyPair = RsaKeyPair.generate();
|
||||
var publicKeyStr = keyPair.publicKeyString(comment: "No Comment");
|
||||
var privateKeyStr = keyPair.privateKeyString();
|
||||
final keyPair = await ed25519.newKeyPair();
|
||||
|
||||
var publicKey = keyPair.publicKey;
|
||||
var privateKey = keyPair.privateKey;
|
||||
|
||||
var publicKeyStr = publicKeyString(publicKey.bytes);
|
||||
var privateKeyStr = ""; //keyPair.privateKeyString();
|
||||
|
||||
print(privateKey);
|
||||
|
||||
var keyName = "key_";
|
||||
var num = 0;
|
||||
@ -20,3 +29,23 @@ void main() {
|
||||
File("key_$num.pub").writeAsStringSync(publicKeyStr + '\n');
|
||||
File("key_$num").writeAsStringSync(privateKeyStr + '\n');
|
||||
}
|
||||
|
||||
String publicKeyString(List<int> publicKeyBytes, {String comment = ""}) {
|
||||
var data = BinaryLengthValue.encode([
|
||||
BinaryLengthValue.fromString("ssh-ed25519"),
|
||||
BinaryLengthValue(publicKeyBytes),
|
||||
]);
|
||||
|
||||
if (comment.isNotEmpty) {
|
||||
comment = comment.replaceAll('\r', ' ');
|
||||
comment = comment.replaceAll('\n', ' ');
|
||||
comment = ' $comment';
|
||||
}
|
||||
|
||||
return 'ssh-ed25519 ${base64.encode(data)}$comment';
|
||||
}
|
||||
|
||||
String privateKeyString() {
|
||||
var str = '-----BEGIN OPENSSH PRIVATE KEY-----\n';
|
||||
return str;
|
||||
}
|
||||
|
21
pubspec.lock
21
pubspec.lock
@ -162,6 +162,20 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.5"
|
||||
cryptography:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: cryptography
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.4.1"
|
||||
cryptography_flutter:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: cryptography_flutter
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.0"
|
||||
crypton:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
@ -339,6 +353,13 @@ packages:
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.2.1"
|
||||
fixnum:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: fixnum
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.10.11"
|
||||
flutter:
|
||||
dependency: "direct main"
|
||||
description: flutter
|
||||
|
@ -22,6 +22,8 @@ dependencies:
|
||||
badges: ^1.1.1
|
||||
connectivity: ^0.4.6+1
|
||||
cached_network_image: ^2.2.0+1
|
||||
cryptography: ^1.4.1
|
||||
cryptography_flutter: ^1.0.0
|
||||
crypton: ^1.1.3
|
||||
device_info: ">=0.4.2+4 <2.0.0"
|
||||
dots_indicator: ^0.0.3
|
||||
|
Reference in New Issue
Block a user