非常教程

Ruby 2.4参考手册

OpenSSL

OpenSSL::PKey

非对称公钥算法

非对称公钥算法解决了建立和共享密钥以解密/解密消息的问题。这种算法的关键在于两部分:可以分发给其他人的公钥和需要保密的私钥。

使用公钥加密的邮件只能由拥有相关私钥的收件人解密。由于公钥算法比对称密钥算法慢得多(参见OpenSSL :: Cipher),它们通常用于建立拥有对方公钥的双方之间共享的对称密钥。

非对称算法提供了许多不同领域使用的很好的功能。一个非常常见的应用是数字签名的创建和验证。为签署文件,签字人通常使用信息摘要算法(参见OpenSSL :: Digest)来计算文件的摘要,然后使用私钥对其进行加密(即签名)。任何拥有公钥的人都可以通过自己计算原始文档的消息摘要来验证签名,使用签名人的公钥对签名进行解密,并将结果与​​之前计算的消息摘要进行比较。当且仅当解密的签名等于此消息摘要时,签名才有效。

PKey模块支持三种流行的公钥/私钥算法:

  • RSA (OpenSSL::PKey::RSA)
  • DSA (OpenSSL::PKey::DSA)
  • Elliptic Curve Cryptography (OpenSSL::PKey::EC)Each of these implementations is in fact a sub-class of the abstract PKey class which offers the interface for supporting digital signatures in the form of OpenSSL::PKey::PKey#sign and OpenSSL::PKey::PKey#verify.Diffie-Hellman Key ExchangeFinally PKey also features OpenSSL::PKey::DH, an implementation of the Diffie-Hellman key exchange protocol based on discrete logarithms in finite fields, the same basis that DSA is built on. The Diffie-Hellman protocol can be used to exchange (symmetric) keys over insecure channels without needing any prior joint knowledge between the participating parties. As the security of DH demands relatively long “public keys” (i.e. the part that is overtly transmitted between participants) DH tends to be quite slow. If security or speed is your primary concern, OpenSSL::PKey::EC offers another implementation of the Diffie-Hellman protocol.Public Class Methods OpenSSL::PKey.read(string , pwd ) → PKey Show source OpenSSL::PKey.read(io , pwd ) → PKey Reads a DER or PEM encoded string from string或者io返回适当的PKey类的实例。参数
  • string 是包含任意私钥或公钥的DER或PEM编码的字符串。
  • io是一个IO包含DER或PEM编码的任意私钥或公钥的实例。
  • pwd是的情况下,可选的密码stringfile是一个加密的PEM资源。
static VALUE
ossl_pkey_new_from_data(int argc, VALUE *argv, VALUE self)
{
    EVP_PKEY *pkey;
    BIO *bio;
    VALUE data, pass;

    rb_scan_args(argc, argv, "11", &data, &pass);
    pass = ossl_pem_passwd_value(pass);

    bio = ossl_obj2bio(data);
    if (!(pkey = d2i_PrivateKey_bio(bio, NULL))) {
        OSSL_BIO_reset(bio);
        if (!(pkey = PEM_read_bio_PrivateKey(bio, NULL, ossl_pem_passwd_cb, (void *)pass))) {
            OSSL_BIO_reset(bio);
            if (!(pkey = d2i_PUBKEY_bio(bio, NULL))) {
                OSSL_BIO_reset(bio);
                pkey = PEM_read_bio_PUBKEY(bio, NULL, ossl_pem_passwd_cb, (void *)pass);
            }
        }
    }

    BIO_free(bio);
    if (!pkey)
        ossl_raise(ePKeyError, "Could not parse PKey");

    return ossl_pkey_new(pkey);
}

OpenSSL相关

1.OpenSSL::ASN1
2.OpenSSL::ASN1::ASN1Data
3.OpenSSL::ASN1::ASN1Error
4.OpenSSL::ASN1::Constructive
5.OpenSSL::ASN1::ObjectId
6.OpenSSL::ASN1::Primitive
7.OpenSSL::BN
8.OpenSSL::BNError
9.OpenSSL::Buffering
10.OpenSSL::Cipher
11.OpenSSL::Cipher::Cipher
12.OpenSSL::Config
13.OpenSSL::ConfigError
14.OpenSSL::Digest
15.OpenSSL::Digest::DigestError
16.OpenSSL::Engine
17.OpenSSL::Engine::EngineError
18.OpenSSL::ExtConfig
19.OpenSSL::HMAC
20.OpenSSL::HMACError
21.OpenSSL::Netscape
22.OpenSSL::Netscape::SPKI
23.OpenSSL::Netscape::SPKIError
24.OpenSSL::OCSP
25.OpenSSL::OCSP::BasicResponse
26.OpenSSL::OCSP::CertificateId
27.OpenSSL::OCSP::OCSPError
28.OpenSSL::OCSP::Request
29.OpenSSL::OCSP::Response
30.OpenSSL::OCSP::SingleResponse
31.OpenSSL::OpenSSLError
32.OpenSSL::PKCS12
33.OpenSSL::PKCS5
34.OpenSSL::PKCS5::PKCS5Error
35.OpenSSL::PKCS7
36.OpenSSL::PKCS7::RecipientInfo
37.OpenSSL::PKCS7::SignerInfo
38.OpenSSL::PKey::DH
39.OpenSSL::PKey::DHError
40.OpenSSL::PKey::DSA
41.OpenSSL::PKey::DSAError
42.OpenSSL::PKey::EC
43.OpenSSL::PKey::EC::Group
44.OpenSSL::PKey::EC::Point
45.OpenSSL::PKey::PKey
46.OpenSSL::PKey::PKeyError
47.OpenSSL::PKey::RSA
48.OpenSSL::PKey::RSAError
49.OpenSSL::Random
50.OpenSSL::SSL
51.OpenSSL::SSL::Session
52.OpenSSL::SSL::SocketForwarder
53.OpenSSL::SSL::SSLContext
54.OpenSSL::SSL::SSLError
55.OpenSSL::SSL::SSLServer
56.OpenSSL::SSL::SSLSocket
57.OpenSSL::X509::Attribute
58.OpenSSL::X509::Certificate
59.OpenSSL::X509::CRL
60.OpenSSL::X509::Extension
61.OpenSSL::X509::ExtensionFactory
62.OpenSSL::X509::Name
63.OpenSSL::X509::Name::RFC2253DN
64.OpenSSL::X509::Request
65.OpenSSL::X509::Revoked
66.OpenSSL::X509::Store
67.OpenSSL::X509::StoreContext
Ruby 2.4

Ruby 是一种面向对象、命令式、函数式、动态的通用编程语言,是世界上最优美而巧妙的语言。

主页 https://www.ruby-lang.org/
源码 https://github.com/ruby/ruby
版本 2.4
发布版本 2.4.1

Ruby 2.4目录

1.缩略 | Abbrev
2.ARGF
3.数组 | Array
4.Base64
5.基本对象 | BasicObject
6.基准测试 | Benchmark
7.BigDecimal
8.绑定 | Binding
9.CGI
10.类 | Class
11.比较 | Comparable
12.负责 | Complex
13.计算续体 | Continuation
14.覆盖 | Coverage
15.CSV
16.日期 | Date
17.日期时间 | DateTime
18.DBM
19.代理 | Delegator
20.摘要 | Digest
21.Dir
22.DRb
23.编码 | Encoding
24.枚举 | Enumerable
25.枚举 | Enumerator
26.ENV
27.ERB
28.错误 | Errors
29.Etc
30.期望值 | Exception
31.错误类 | FalseClass
32.Fiber
33.Fiddle
34.文件 | File
35.文件实用程序 | FileUtils
36.查找 | Find
37.浮点 | Float
38.Forwardable
39.GC
40.GDBM
41.GetoptLong
42.Hash
43.Integer
44.IO
45.IPAddr
46.JSON
47.Kernel
48.语言 | 3Language
49.记录 | Logger
50.编排 | Marshal
51.MatchData
52.数学 | Math
53.矩阵 | Matrix
54.方法 | Method
55.模型 | Module
56.监控 | Monitor
57. 互斥 | Mutex
58.Net
59.Net::FTP
60.Net::HTTP
61.Net::IMAP
62.Net::SMTP
63.NilClass
64.数字 | Numeric
65.对象 | Object
66.ObjectSpace
67.Observable
68.Open3
69.OpenSSL
70.OpenStruct
71.OpenURI
72.OptionParser
73.路径名 | Pathname
74.完整输出 | PrettyPrint
75.Prime
76.Proc
77.过程 | Process
78.PStore
79.PTY
80.队列 | Queue
81.随机 | Random
82.范围 | Range
83.合理的 | Rational
84.Readline
85.Regexp
86.Resolv
87.Ripper
88.RubyVM
89.Scanf
90.SDBM
91.SecureRandom
92.Set
93.Shell
94.信号 | Signal
95.Singleton
96.套接字 | Socket
97.字符串 | String
98.StringIO
99.StringScanner
100.结构 | Struct