mirror of
				https://github.com/ruby/ruby.git
				synced 2022-11-09 12:17:21 -05:00 
			
		
		
		
	[ruby/openssl] pkey: prefer PKey.read over PKey::RSA.new in docs
cf92a3ffba
			
			
This commit is contained in:
		
							parent
							
								
									efad0166c6
								
							
						
					
					
						commit
						10d360847b
					
				
				
				Notes:
				
					git
				
				2021-03-16 20:38:54 +09:00 
				
			
			
			
		
		
					 6 changed files with 8 additions and 8 deletions
				
			
		| 
						 | 
					@ -682,13 +682,13 @@ ossl_crypto_fixed_length_secure_compare(VALUE dummy, VALUE str1, VALUE str2)
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * A key can also be loaded from a file.
 | 
					 * A key can also be loaded from a file.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 *   key2 = OpenSSL::PKey::RSA.new File.read 'private_key.pem'
 | 
					 *   key2 = OpenSSL::PKey.read File.read 'private_key.pem'
 | 
				
			||||||
 *   key2.public? # => true
 | 
					 *   key2.public? # => true
 | 
				
			||||||
 *   key2.private? # => true
 | 
					 *   key2.private? # => true
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * or
 | 
					 * or
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 *   key3 = OpenSSL::PKey::RSA.new File.read 'public_key.pem'
 | 
					 *   key3 = OpenSSL::PKey.read File.read 'public_key.pem'
 | 
				
			||||||
 *   key3.public? # => true
 | 
					 *   key3.public? # => true
 | 
				
			||||||
 *   key3.private? # => false
 | 
					 *   key3.private? # => false
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
| 
						 | 
					@ -700,7 +700,7 @@ ossl_crypto_fixed_length_secure_compare(VALUE dummy, VALUE str1, VALUE str2)
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 *   key4_pem = File.read 'private.secure.pem'
 | 
					 *   key4_pem = File.read 'private.secure.pem'
 | 
				
			||||||
 *   pass_phrase = 'my secure pass phrase goes here'
 | 
					 *   pass_phrase = 'my secure pass phrase goes here'
 | 
				
			||||||
 *   key4 = OpenSSL::PKey::RSA.new key4_pem, pass_phrase
 | 
					 *   key4 = OpenSSL::PKey.read key4_pem, pass_phrase
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * == RSA Encryption
 | 
					 * == RSA Encryption
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -15,7 +15,7 @@ ca_path   = options["C"]
 | 
				
			||||||
ctx = OpenSSL::SSL::SSLContext.new()
 | 
					ctx = OpenSSL::SSL::SSLContext.new()
 | 
				
			||||||
if cert_file && key_file
 | 
					if cert_file && key_file
 | 
				
			||||||
  ctx.cert = OpenSSL::X509::Certificate.new(File::read(cert_file))
 | 
					  ctx.cert = OpenSSL::X509::Certificate.new(File::read(cert_file))
 | 
				
			||||||
  ctx.key  = OpenSSL::PKey::RSA.new(File::read(key_file))
 | 
					  ctx.key  = OpenSSL::PKey.read(File::read(key_file))
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
if ca_path
 | 
					if ca_path
 | 
				
			||||||
  ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER
 | 
					  ctx.verify_mode = OpenSSL::SSL::VERIFY_PEER
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -13,7 +13,7 @@ ca_path   = options["C"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if cert_file && key_file
 | 
					if cert_file && key_file
 | 
				
			||||||
  cert = OpenSSL::X509::Certificate.new(File::read(cert_file))
 | 
					  cert = OpenSSL::X509::Certificate.new(File::read(cert_file))
 | 
				
			||||||
  key  = OpenSSL::PKey::RSA.new(File::read(key_file))
 | 
					  key  = OpenSSL::PKey.read(File::read(key_file))
 | 
				
			||||||
else
 | 
					else
 | 
				
			||||||
  key = OpenSSL::PKey::RSA.new(512){ print "." }
 | 
					  key = OpenSSL::PKey::RSA.new(512){ print "." }
 | 
				
			||||||
  puts
 | 
					  puts
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -25,7 +25,7 @@ name = X509::Name.parse(name_str)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
keypair = nil
 | 
					keypair = nil
 | 
				
			||||||
if keypair_file
 | 
					if keypair_file
 | 
				
			||||||
  keypair = PKey::RSA.new(File.open(keypair_file).read)
 | 
					  keypair = PKey.read(File.read(keypair_file))
 | 
				
			||||||
else
 | 
					else
 | 
				
			||||||
  keypair = PKey::RSA.new(1024) { putc "." }
 | 
					  keypair = PKey::RSA.new(1024) { putc "." }
 | 
				
			||||||
  puts
 | 
					  puts
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -11,7 +11,7 @@ ca_path   = options["C"]
 | 
				
			||||||
data = $stdin.read
 | 
					data = $stdin.read
 | 
				
			||||||
 | 
					
 | 
				
			||||||
cert = X509::Certificate.new(File::read(cert_file))
 | 
					cert = X509::Certificate.new(File::read(cert_file))
 | 
				
			||||||
key = PKey::RSA.new(File::read(key_file))
 | 
					key = PKey::read(File::read(key_file))
 | 
				
			||||||
p7enc = PKCS7::read_smime(data)
 | 
					p7enc = PKCS7::read_smime(data)
 | 
				
			||||||
data = p7enc.decrypt(key, cert)
 | 
					data = p7enc.decrypt(key, cert)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -9,7 +9,7 @@ key_file  = options["k"]
 | 
				
			||||||
rcpt_file = options["r"]
 | 
					rcpt_file = options["r"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
cert = X509::Certificate.new(File::read(cert_file))
 | 
					cert = X509::Certificate.new(File::read(cert_file))
 | 
				
			||||||
key = PKey::RSA.new(File::read(key_file))
 | 
					key = PKey::read(File::read(key_file))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
data  = "Content-Type: text/plain\r\n"
 | 
					data  = "Content-Type: text/plain\r\n"
 | 
				
			||||||
data << "\r\n"
 | 
					data << "\r\n"
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue