38 lines
1.0 KiB
GDScript
38 lines
1.0 KiB
GDScript
extends Node
|
|
|
|
var computer_a = {
|
|
"crypto": Crypto.new(),
|
|
"private_key": null,
|
|
"peer_public_key": null,
|
|
}
|
|
|
|
var computer_b = {
|
|
"crypto": Crypto.new(),
|
|
"private_key": null,
|
|
"peer_public_key": null,
|
|
}
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
func _ready() -> void:
|
|
computer_a["private_key"] = computer_a["crypto"].generate_rsa(2048)
|
|
computer_b["private_key"] = computer_b["crypto"].generate_rsa(2048)
|
|
var a_pub_key: String = computer_a["private_key"].save_to_string(true)
|
|
print(len(a_pub_key))
|
|
var b_pub_key = computer_b["private_key"].save_to_string(true)
|
|
|
|
var key_a = CryptoKey.new()
|
|
key_a.load_from_string(b_pub_key, true)
|
|
var key_b = CryptoKey.new()
|
|
key_b.load_from_string(a_pub_key, true)
|
|
|
|
computer_a["peer_public_key"] = key_a
|
|
computer_b["peer_public_key"] = key_b
|
|
|
|
var encrypted: PackedByteArray = computer_a["crypto"].encrypt(computer_a["peer_public_key"], "This is a test".to_utf8_buffer())
|
|
var decrypted = computer_b["crypto"].decrypt(computer_b["private_key"], encrypted).get_string_from_utf8()
|
|
print(encrypted)
|
|
print(decrypted)
|