Class: Ccrypto::Java::X25519PrivateKey

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

Overview

X25519PublicKey

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



66
67
68
69
70
71
72
73
# File 'lib/ccrypto/java/engines/x25519_engine.rb', line 66

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

.to_key(bin, &block) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ccrypto/java/engines/x25519_engine.rb', line 46

def self.to_key(bin, &block)
  if block
    prov = block.call(:jce_provider)
  else
    prov = JCEProvider::BCProv
  end

  kf = java.security.KeyFactory.getInstance("X25519",prov)
  priv = kf.generate_private(java.security.spec.PKCS8EncodedKeySpec.new(bin))
  X25519PrivateKey.new(priv)

end

Instance Method Details

#equals?(privKey) ⇒ Boolean Also known as: key_equals?

Returns:

  • (Boolean)


75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/ccrypto/java/engines/x25519_engine.rb', line 75

def equals?(privKey)
  if not @native_privKey.nil?
    case privKey
    when X25519PrivateKey
      @native_privKey.encoded == privKey.to_bin
    else
      logger.warn "Unmatched private key : (native) #{@native_privKey} vs. (subject) #{privKey}"
      false
    end
  else
    logger.warn "X25519PrivateKey equals? returned false because native_privKey is nil"
    false
  end
end

#to_binObject



42
43
44
# File 'lib/ccrypto/java/engines/x25519_engine.rb', line 42

def to_bin
  @native_privKey.encoded  
end

#to_pemObject



59
60
61
62
63
64
# File 'lib/ccrypto/java/engines/x25519_engine.rb', line 59

def to_pem
  cont = ["-----BEGIN X25519 PRIVATE KEY-----\n"]
  cont << to_b64(@native_privKey.encoded)
  cont << "\n-----END X25519 PRIVATE KEY-----"
  cont.join
end