Class: Ccrypto::Java::ED25519PublicKey

Inherits:
ED25519PublicKey
  • Object
show all
Includes:
DataConversion
Defined in:
lib/ccrypto/java/engines/ed25519_engine.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DataConversion

#from_b64, #from_b64_mime, #from_hex, included, #logger, #to_b64, #to_b64_mime, #to_hex, #to_java_bytes, #to_str

Class Method Details

.from_pem(str) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/ccrypto/java/engines/ed25519_engine.rb', line 26

def self.from_pem(str)
  if str =~ /ED25519 PUBLIC/
    cont = str.lines[1..-2].join.strip
    to_key(from_b64(cont))
  else
    raise KeypairEngineException, "Not an ED25519 public key"
  end
end

.to_key(bin) ⇒ Object



14
15
16
17
# File 'lib/ccrypto/java/engines/ed25519_engine.rb', line 14

def self.to_key(bin)
  pubKey = java.security.KeyFactory.getInstance("ED25519", "BC").generatePublic(java.security.spec.X509EncodedKeySpec.new(bin))
  ED25519PublicKey.new(pubKey)
end

Instance Method Details

#to_binObject



10
11
12
# File 'lib/ccrypto/java/engines/ed25519_engine.rb', line 10

def to_bin
  @native_pubKey.encoded
end

#to_pemObject



19
20
21
22
23
24
# File 'lib/ccrypto/java/engines/ed25519_engine.rb', line 19

def to_pem
  cont = ["-----BEGIN ED25519 PUBLIC KEY-----\n"]
  cont << to_b64(to_bin)
  cont << "\n-----END ED25519 PUBLIC KEY-----"
  cont.join
end