Class: Ccrypto::Java::ECCPublicKey
- Inherits:
-
ECCPublicKey
- Object
- ECCPublicKey
- Ccrypto::Java::ECCPublicKey
show all
- Includes:
- DataConversion
- Defined in:
- lib/ccrypto/java/engines/ecc_engine.rb
Class Method Summary
collapse
Instance Method Summary
collapse
#from_b64, #from_b64_mime, #from_hex, included, #to_b64, #to_b64_mime, #to_hex, #to_java_bytes, #to_str
Constructor Details
#initialize(kp, curve) ⇒ ECCPublicKey
Returns a new instance of ECCPublicKey.
12
13
14
15
|
# File 'lib/ccrypto/java/engines/ecc_engine.rb', line 12
def initialize(kp, curve)
super(kp)
@curve = curve
end
|
Class Method Details
.from_pem(str) ⇒ Object
44
45
46
47
48
49
50
51
|
# File 'lib/ccrypto/java/engines/ecc_engine.rb', line 44
def self.from_pem(str)
if str =~ /ECC PUBLIC/
cont = str.lines[1..-2].join.strip
to_key(from_b64(cont))
else
raise KeypairEngineException, "Not an ECC public key"
end
end
|
.to_key(bin) ⇒ Object
from binary to public key object
54
55
56
57
58
59
60
|
# File 'lib/ccrypto/java/engines/ecc_engine.rb', line 54
def self.to_key(bin)
bin = to_java_bytes(bin) if not bin.is_a?(::Java::byte[])
pubKey = java.security.KeyFactory.getInstance("ECDSA", "BC").generatePublic(java.security.spec.X509EncodedKeySpec.new(bin))
curve = pubKey.params.name
ECCPublicKey.new(pubKey, curve)
end
|
Instance Method Details
#curve ⇒ Object
17
18
19
|
# File 'lib/ccrypto/java/engines/ecc_engine.rb', line 17
def curve
@curve
end
|
#encoded ⇒ Object
33
34
35
|
# File 'lib/ccrypto/java/engines/ecc_engine.rb', line 33
def encoded
to_bin
end
|
#equals?(pubKey) ⇒ Boolean
Also known as:
key_equals?
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/ccrypto/java/engines/ecc_engine.rb', line 62
def equals?(pubKey)
if not @native_pubKey.nil?
case pubKey
when ECCPublicKey
@native_pubKey.encoded == pubKey.to_bin
else
logger.warn "Unmatched public key : (native) #{@native_pubKey} vs. (subject) #{pubKey}"
false
end
else
logger.warn "ECCPublicKey equals? returned false because native_pubKey is nil"
false
end
end
|
#to_bin(enc = :bin) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/ccrypto/java/engines/ecc_engine.rb', line 21
def to_bin(enc = :bin)
res = @native_pubKey.encoded
case enc
when :b64, :base64
to_b64(res)
when :hex
to_hex(res)
else
res
end
end
|
#to_pem ⇒ Object
37
38
39
40
41
42
|
# File 'lib/ccrypto/java/engines/ecc_engine.rb', line 37
def to_pem
cont = ["-----BEGIN ECC PUBLIC KEY-----\n"]
cont << to_b64(to_bin)
cont << "\n-----END ECC PUBLIC KEY-----"
cont.join
end
|