Class: Ccrypto::Java::SecretKeyEngine
- Inherits:
-
Object
- Object
- Ccrypto::Java::SecretKeyEngine
show all
- Includes:
- DataConversion, TR::CondUtils
- Defined in:
- lib/ccrypto/java/engines/secret_key_engine.rb
Class Method Summary
collapse
#from_b64, #from_b64_mime, #from_hex, included, #logger, #to_b64, #to_b64_mime, #to_bin, #to_hex, #to_java_bytes, #to_str
Class Method Details
.find_supported_secret_key_config(algo, keysize = nil) ⇒ Object
24
25
26
27
|
# File 'lib/ccrypto/java/engines/secret_key_engine.rb', line 24
def self.find_supported_secret_key_config(algo, keysize = nil)
res = supported_secret_key_config_table[algo] || {}
res[keysize] || nil
end
|
.generate(*args, &block) ⇒ Object
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/ccrypto/java/engines/secret_key_engine.rb', line 58
def self.generate(*args, &block)
config = args.first
raise SecretKeyEngineException, "KeyConfig is expected but got '#{config.class.name}'" if not config.is_a?(Ccrypto::KeyConfig)
raise SecretKeyEngineException, "Provider initialized KeyConfig is expected" if is_empty?(config.provider_config)
if block
kgProv = block.call(:keygen_jceProvider)
ranProv = block.call(:random_jceProvider)
else
kgProv = config.provider_config[:key_jce_provider] || JCEProvider::DEFProv
end
if kgProv.nil?
logger.debug "KeyGen using algo #{config.algo.to_s} with null provider"
keyGen = javax.crypto.KeyGenerator.getInstance(config.provider_config[:keygen_algo])
else
logger.debug "KeyGen using algo #{config.algo.to_s} with provider #{kgProv.is_a?(String) ? kgProv : kgProv.name}"
keyGen = javax.crypto.KeyGenerator.getInstance(config.provider_config[:keygen_algo], kgProv)
end
if ranProv.nil?
logger.debug "Init KeyGen with keysize #{config.keysize.to_i}"
keyGen.init(config.keysize.to_i)
else
logger.debug "Init KeyGen with keysize #{config.keysize.to_i} with provider #{ranProv.is_a?(String) ? ranProv : ranProv.name}"
keyGen.init(config.keysize.to_i, ranProv)
end
key = keyGen.generateKey
logger.debug "Secret key #{config} generated"
sk = Ccrypto::SecretKey.new(config.algo, config.keysize, key)
sk.provider_config = config.provider_config
sk
end
|
.is_secret_key_config_supported?(algo, keysize = nil) ⇒ Boolean
29
30
31
|
# File 'lib/ccrypto/java/engines/secret_key_engine.rb', line 29
def self.is_secret_key_config_supported?(algo, keysize = nil)
not find_supported_secret_key_config(algo. keysize).nil?
end
|
.secret_key_from_bin(bin, algo, keysize) ⇒ Object
95
96
97
98
99
100
|
# File 'lib/ccrypto/java/engines/secret_key_engine.rb', line 95
def self.secret_key_from_bin(bin, algo, keysize)
raise SecretKeyEngineException, "No data given to convert to secret key" if is_empty?(bin)
raise SecretKeyEngineException, "Algo cannot be empty" if is_empty?(algo)
Ccrypto::SecretKey.new(algo, keysize, javax.crypto.spec.SecretKeySpec.new(to_java_bytes(bin), algo.to_s))
end
|
.supported_secret_key_configs ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/ccrypto/java/engines/secret_key_engine.rb', line 12
def self.supported_secret_key_configs
if @supKeyConf.nil?
@supKeyConf = []
supported_secret_key_config_table.each do |algo, keysize|
keysize.each do |k,v|
@supKeyConf << v
end
end
end
@supKeyConf
end
|