Class: Ed25519Key
Instance Attribute Summary collapse
Instance Method Summary
collapse
account_hash_from_byte_to_hex, byte_hash
Constructor Details
Returns a new instance of Ed25519Key.
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/crypto/ed25519_key.rb', line 20
def initialize()
@file_path = "#{Dir.home}/ed25519_secret_key.pem"
@privKey = Chilkat::CkPrivateKey.new()
success = @privKey.LoadAnyFormatFile(@file_path,"")
if (success == false)
print @privKey.lastErrorText() + "\n";
exit
end
@signature_algorithm = @privKey.keyType()
@private_key_bit_length = @privKey.get_BitLength
sbPubKeyHex = Chilkat::CkStringBuilder.new()
@private_key_hex = @privKey.getRawHex(sbPubKeyHex)
@public_key_hex = sbPubKeyHex.getAsString()
success = @privKey.LoadEd25519(@private_key_hex, @public_key_hex)
if (success == false)
print @privKey.lastErrorText() + "\n";
exit
end
end
|
Instance Attribute Details
#private_key_hex ⇒ Object
attr_reader :public_key, :private_key, :signature_algorithm
16
17
18
|
# File 'lib/crypto/ed25519_key.rb', line 16
def private_key_hex
@private_key_hex
end
|
#privKey ⇒ Object
attr_reader :public_key, :private_key, :signature_algorithm
16
17
18
|
# File 'lib/crypto/ed25519_key.rb', line 16
def privKey
@privKey
end
|
#public_key_hex ⇒ Object
attr_reader :public_key, :private_key, :signature_algorithm
16
17
18
|
# File 'lib/crypto/ed25519_key.rb', line 16
def public_key_hex
@public_key_hex
end
|
#signature_algorithm ⇒ Object
attr_reader :public_key, :private_key, :signature_algorithm
16
17
18
|
# File 'lib/crypto/ed25519_key.rb', line 16
def signature_algorithm
@signature_algorithm
end
|
Instance Method Details
#create_from_private_key_file(private_key_path) ⇒ Object
127
128
129
|
# File 'lib/crypto/ed25519_key.rb', line 127
def create_from_private_key_file(private_key_path)
end
|
#export_private_key_in_pem ⇒ Object
134
135
|
# File 'lib/crypto/ed25519_key.rb', line 134
def export_private_key_in_pem
end
|
#export_public_key_in_pem ⇒ Object
131
132
|
# File 'lib/crypto/ed25519_key.rb', line 131
def export_public_key_in_pem
end
|
#get_private_key ⇒ Object
56
57
58
59
|
# File 'lib/crypto/ed25519_key.rb', line 56
def get_private_key
raise ArgumentError, "Expected a 64 character hex String" unless @private_key_hex.length == 64
return @private_key_hex
end
|
Returns an encoded string, as specified by the encoding argument.
62
63
64
65
|
# File 'lib/crypto/ed25519_key.rb', line 62
def get_private_key_base_encoded_format(encoding)
privKey.getPkcs1ENC(encoding)
end
|
#get_public_key ⇒ Object
51
52
53
54
|
# File 'lib/crypto/ed25519_key.rb', line 51
def get_public_key
raise ArgumentError, "Expected a 64 character hex String" unless @public_key_hex.length == 64
return "01" + @public_key_hex
end
|
#parse_private_key(private_key) ⇒ Object
141
142
|
# File 'lib/crypto/ed25519_key.rb', line 141
def parse_private_key(private_key)
end
|
#private_to_public_key(private_key) ⇒ Object
138
139
|
# File 'lib/crypto/ed25519_key.rb', line 138
def private_to_public_key(private_key)
end
|
#public_key ⇒ Object
112
113
114
115
116
117
|
# File 'lib/crypto/ed25519_key.rb', line 112
def public_key
if @signature_algorithm == "ed25519" && @private_key_hex.length == 64
prefix = "01"
@public_key = prefix + @public_key_hex
end
end
|
#sign(message) ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/crypto/ed25519_key.rb', line 67
def sign(message)
success = @privKey.LoadEd25519(@private_key_hex, @public_key_hex)
if (success == false)
print @privKey.lastErrorText() + "\n";
exit
end
@message = message
byteData = Chilkat::CkByteData.new()
byteData.appendEncoded(@message, "hex");
@bd = Chilkat::CkBinData.new()
@bd.AppendBinary(byteData)
@signer = Chilkat::CkEdDSA.new()
@signature = @signer.signBdENC(@bd, "hexlower", @privKey)
if @signature_algorithm == "ed25519"
@prefix = "0#{CLPublicKeyTag[:ED25519]}"
@signature = @prefix + @signature
end
@signature
end
|
#verify(signature, message) ⇒ Object
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/crypto/ed25519_key.rb', line 93
def verify(signature, message)
pubKey = Chilkat::CkPublicKey.new()
success = pubKey.LoadEd25519(@public_key_hex)
if (success == false)
print pubKey.lastErrorText() + "\n";
exit
end
signature = signature[2...]
verified = @signer.VerifyBdENC(@bd, signature, "hex", pubKey);
if (verified == false)
print @signer.lastErrorText() + "\n";
print "Failed to verify the signature." + "\n";
exit
end
return true
end
|