Class: Ccrypto::Java::RSAPrivateKey
- Inherits:
-
RSAPrivateKey
- Object
- RSAPrivateKey
- Ccrypto::Java::RSAPrivateKey
show all
- Includes:
- DataConversion
- Defined in:
- lib/ccrypto/java/engines/rsa_engine.rb
Class Method Summary
collapse
Instance Method Summary
collapse
#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
65
66
67
68
69
70
71
72
|
# File 'lib/ccrypto/java/engines/rsa_engine.rb', line 65
def self.from_pem(str)
if str =~ /RSA PRIVATE/
cont = str.lines[1..-2].join.strip
to_key(from_b64(cont))
else
raise KeypairEngineException, "Not an RSA private key"
end
end
|
.to_key(bin, &block) ⇒ Object
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/ccrypto/java/engines/rsa_engine.rb', line 45
def self.to_key(bin, &block)
if block
prov = block.call(:jce_provider)
else
prov = JCEProvider::BCProv
end
kf = java.security.KeyFactory.getInstance("RSA",prov)
priv = kf.generate_private(java.security.spec.PKCS8EncodedKeySpec.new(bin))
RSAPrivateKey.new(priv)
end
|
Instance Method Details
#equals?(privKey) ⇒ Boolean
Also known as:
key_equals?
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'lib/ccrypto/java/engines/rsa_engine.rb', line 78
def equals?(privKey)
if not @native_privKey.nil?
case privKey
when RSAPrivateKey
@native_privKey.encoded == privKey.to_bin
else
logger.warn "Unmatched private key : (native) #{@native_privKey} vs. (subject) #{privKey}"
false
end
else
logger.warn "RSAPrivateKey equals? returned false because native_privKey is nil"
false
end
end
|
#to_bin ⇒ Object
74
75
76
|
# File 'lib/ccrypto/java/engines/rsa_engine.rb', line 74
def to_bin
@native_privKey.encoded
end
|
#to_pem ⇒ Object
58
59
60
61
62
63
|
# File 'lib/ccrypto/java/engines/rsa_engine.rb', line 58
def to_pem
cont = ["-----BEGIN RSA PRIVATE KEY-----\n"]
cont << to_b64(@native_privKey.encoded)
cont << "\n-----END RSA PRIVATE KEY-----"
cont.join
end
|