Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
class method
Gem::Security.write_private_key
write_private_key(key, path, permissions = 0o600, passphrase = nil, cipher = KEY_CIPHER)
lib/rubygems/security.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/lib/rubygems/security.rb, line 679
def self.write_private_key(key, path, permissions = 0o600, passphrase = nil, cipher = KEY_CIPHER)
path = File.expand_path path
File.open path, "wb", permissions do |io|
if passphrase && cipher
io.write key.private_to_pem cipher, passphrase
else
io.write key.private_to_pem
end
end
path
end
Writes the private key to path with the given permissions. If passed passphrase and cipher, the key is encrypted.