<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                # package rsa `import "crypto/rsa"` rsa包實現了PKCS#1規定的RSA加密算法。 ## Index * [Constants](#pkg-constants) * [Variables](#pkg-variables) * [type CRTValue](#CRTValue) * [type PrecomputedValues](#PrecomputedValues) * [type PublicKey](#PublicKey) * [type PrivateKey](#PrivateKey) * [func GenerateKey(random io.Reader, bits int) (priv \*PrivateKey, err error)](#GenerateKey) * [func GenerateMultiPrimeKey(random io.Reader, nprimes int, bits int) (priv \*PrivateKey, err error)](#GenerateMultiPrimeKey) * [func (priv \*PrivateKey) Precompute()](#PrivateKey.Precompute) * [func (priv \*PrivateKey) Validate() error](#PrivateKey.Validate) * [type PSSOptions](#PSSOptions) * [func EncryptOAEP(hash hash.Hash, random io.Reader, pub \*PublicKey, msg []byte, label []byte) (out []byte, err error)](#EncryptOAEP) * [func DecryptOAEP(hash hash.Hash, random io.Reader, priv \*PrivateKey, ciphertext []byte, label []byte) (msg []byte, err error)](#DecryptOAEP) * [func EncryptPKCS1v15(rand io.Reader, pub \*PublicKey, msg []byte) (out []byte, err error)](#EncryptPKCS1v15) * [func DecryptPKCS1v15(rand io.Reader, priv \*PrivateKey, ciphertext []byte) (out []byte, err error)](#DecryptPKCS1v15) * [func DecryptPKCS1v15SessionKey(rand io.Reader, priv \*PrivateKey, ciphertext []byte, key []byte) (err error)](#DecryptPKCS1v15SessionKey) * [func SignPKCS1v15(rand io.Reader, priv \*PrivateKey, hash crypto.Hash, hashed []byte) (s []byte, err error)](#SignPKCS1v15) * [func VerifyPKCS1v15(pub \*PublicKey, hash crypto.Hash, hashed []byte, sig []byte) (err error)](#VerifyPKCS1v15) * [func SignPSS(rand io.Reader, priv \*PrivateKey, hash crypto.Hash, hashed []byte, opts \*PSSOptions) (s []byte, err error)](#SignPSS) * [func VerifyPSS(pub \*PublicKey, hash crypto.Hash, hashed []byte, sig []byte, opts \*PSSOptions) error](#VerifyPSS) ## Constants ``` const ( // PSSSaltLengthAuto讓PSS簽名在簽名時讓鹽盡可能長,并在驗證時自動檢測出鹽。 PSSSaltLengthAuto = 0 // PSSSaltLengthEqualsHash讓鹽的長度和用于簽名的哈希值的長度相同。 PSSSaltLengthEqualsHash = -1 ) ``` ## Variables ``` var ErrDecryption = errors.New("crypto/rsa: decryption error") ``` ErrDecryption代表解密數據失敗。它故意寫的語焉不詳,以避免適應性攻擊。 ``` var ErrMessageTooLong = errors.New("crypto/rsa: message too long for RSA public key size") ``` 當試圖用公鑰加密尺寸過大的數據時,就會返回ErrMessageTooLong。 ``` var ErrVerification = errors.New("crypto/rsa: verification error") ``` ErrVerification代表認證簽名失敗。它故意寫的語焉不詳,以避免適應性攻擊。 ## type [CRTValue](https://github.com/golang/go/blob/master/src/crypto/rsa/rsa.go#L73 "View Source") ``` type CRTValue struct { Exp *big.Int // D mod (prime-1). Coeff *big.Int // R·Coeff ≡ 1 mod Prime. R *big.Int // product of primes prior to this (inc p and q). } ``` CRTValue包含預先計算的中國剩余定理的值。 ## type [PrecomputedValues](https://github.com/golang/go/blob/master/src/crypto/rsa/rsa.go#L61 "View Source") ``` type PrecomputedValues struct { Dp, Dq *big.Int // D mod (P-1) (or mod Q-1) Qinv *big.Int // Q^-1 mod P // CRTValues用于保存第3個及其余的素數的預計算值。 // 因為歷史原因,頭兩個素數的CRT在PKCS#1中的處理是不同的。 // 因為互操作性十分重要,我們鏡像了這些素數的預計算值。 CRTValues []CRTValue } ``` ## type [PublicKey](https://github.com/golang/go/blob/master/src/crypto/rsa/rsa.go#L21 "View Source") ``` type PublicKey struct { N *big.Int // 模 E int // 公開的指數 } ``` 代表一個RSA公鑰。 ## type [PrivateKey](https://github.com/golang/go/blob/master/src/crypto/rsa/rsa.go#L51 "View Source") ``` type PrivateKey struct { PublicKey // 公鑰 D *big.Int // 私有的指數 Primes []*big.Int // N的素因子,至少有兩個 // 包含預先計算好的值,可在某些情況下加速私鑰的操作 Precomputed PrecomputedValues } ``` 代表一個RSA私鑰。 ### func [GenerateKey](https://github.com/golang/go/blob/master/src/crypto/rsa/rsa.go#L125 "View Source") ``` func GenerateKey(random io.Reader, bits int) (priv *PrivateKey, err error) ``` GenerateKey函數使用隨機數據生成器random生成一對具有指定字位數的RSA密鑰。 ### func [GenerateMultiPrimeKey](https://github.com/golang/go/blob/master/src/crypto/rsa/rsa.go#L140 "View Source") ``` func GenerateMultiPrimeKey(random io.Reader, nprimes int, bits int) (priv *PrivateKey, err error) ``` GenerateMultiPrimeKey使用指定的字位數生成一對多質數的RSA密鑰,參見US patent 4405829。雖然公鑰可以和二質數情況下的公鑰兼容(事實上,不能區分兩種公鑰),私鑰卻不行。因此有可能無法生成特定格式的多質數的密鑰對,或不能將生成的密鑰用在其他(語言的)代碼里。 [http://www.cacr.math.uwaterloo.ca/techreports/2006/cacr2006-16.pdf](http://www.cacr.math.uwaterloo.ca/techreports/2006/cacr2006-16.pdf)中的Table 1說明了給定字位數的密鑰可以接受的質數最大數量。 ### func (\*PrivateKey) [Precompute](https://github.com/golang/go/blob/master/src/crypto/rsa/rsa.go#L348 "View Source") ``` func (priv *PrivateKey) Precompute() ``` Precompute方法會預先進行一些計算,以加速未來的私鑰的操作。 ### func (\*PrivateKey) [Validate](https://github.com/golang/go/blob/master/src/crypto/rsa/rsa.go#L81 "View Source") ``` func (priv *PrivateKey) Validate() error ``` Validate方法進行密鑰的完整性檢查。如果密鑰合法會返回nil,否則會返回說明問題的error值。 ## type [PSSOptions](https://github.com/golang/go/blob/master/src/crypto/rsa/pss.go#L220 "View Source") ``` type PSSOptions struct { // SaltLength控制PSS簽名中加鹽的長度,可以是字節數,或者某個PSS鹽長度的常數 SaltLength int } ``` PSSOptions包含用于創建和認證PSS簽名的參數。 ## func [EncryptOAEP](https://github.com/golang/go/blob/master/src/crypto/rsa/rsa.go#L268 "View Source") ``` func EncryptOAEP(hash hash.Hash, random io.Reader, pub *PublicKey, msg []byte, label []byte) (out []byte, err error) ``` 采用RSA-OAEP算法加密給出的數據。數據不能超過((公共模數的長度)-2*( hash長度)+2)字節。 ## func [DecryptOAEP](https://github.com/golang/go/blob/master/src/crypto/rsa/rsa.go#L457 "View Source") ``` func DecryptOAEP(hash hash.Hash, random io.Reader, priv *PrivateKey, ciphertext []byte, label []byte) (msg []byte, err error) ``` DecryptOAEP解密RSA-OAEP算法加密的數據。如果random不是nil,函數會注意規避時間側信道攻擊。 ## func [EncryptPKCS1v15](https://github.com/golang/go/blob/master/src/crypto/rsa/pkcs1v15.go#L21 "View Source") ``` func EncryptPKCS1v15(rand io.Reader, pub *PublicKey, msg []byte) (out []byte, err error) ``` EncryptPKCS1v15使用PKCS#1 v1.5規定的填充方案和RSA算法加密msg。信息不能超過((公共模數的長度)-11)字節。注意:使用本函數加密明文(而不是會話密鑰)是危險的,請盡量在新協議中使用RSA OAEP。 ## func [DecryptPKCS1v15](https://github.com/golang/go/blob/master/src/crypto/rsa/pkcs1v15.go#L52 "View Source") ``` func DecryptPKCS1v15(rand io.Reader, priv *PrivateKey, ciphertext []byte) (out []byte, err error) ``` DecryptPKCS1v15使用PKCS#1 v1.5規定的填充方案和RSA算法解密密文。如果random不是nil,函數會注意規避時間側信道攻擊。 ## func [DecryptPKCS1v15SessionKey](https://github.com/golang/go/blob/master/src/crypto/rsa/pkcs1v15.go#L80 "View Source") ``` func DecryptPKCS1v15SessionKey(rand io.Reader, priv *PrivateKey, ciphertext []byte, key []byte) (err error) ``` DecryptPKCS1v15SessionKey使用PKCS#1 v1.5規定的填充方案和RSA算法解密會話密鑰。如果random不是nil,函數會注意規避時間側信道攻擊。 如果密文長度不對,或者如果密文比公共模數的長度還長,會返回錯誤;否則,不會返回任何錯誤。如果填充是合法的,生成的明文信息會拷貝進key;否則,key不會被修改。這些情況都會在固定時間內出現(規避時間側信道攻擊)。本函數的目的是讓程序的使用者事先生成一個隨機的會話密鑰,并用運行時的值繼續協議。這樣可以避免任何攻擊者從明文竊取信息的可能性。 參見”Chosen Ciphertext Attacks Against Protocols Based on the RSA Encryption Standard PKCS #1”。 ## func [SignPKCS1v15](https://github.com/golang/go/blob/master/src/crypto/rsa/pkcs1v15.go#L194 "View Source") ``` func SignPKCS1v15(rand io.Reader, priv *PrivateKey, hash crypto.Hash, hashed []byte) (s []byte, err error) ``` SignPKCS1v15使用RSA PKCS#1 v1.5規定的RSASSA-PKCS1-V1_5-SIGN簽名方案計算簽名。注意hashed必須是使用提供給本函數的hash參數對(要簽名的)原始數據進行hash的結果。 ## func [VerifyPKCS1v15](https://github.com/golang/go/blob/master/src/crypto/rsa/pkcs1v15.go#L231 "View Source") ``` func VerifyPKCS1v15(pub *PublicKey, hash crypto.Hash, hashed []byte, sig []byte) (err error) ``` VerifyPKCS1v15認證RSA PKCS#1 v1.5簽名。hashed是使用提供的hash參數對(要簽名的)原始數據進行hash的結果。合法的簽名會返回nil,否則表示簽名不合法。 ## func [SignPSS](https://github.com/golang/go/blob/master/src/crypto/rsa/pss.go#L238 "View Source") ``` func SignPSS(rand io.Reader, priv *PrivateKey, hash crypto.Hash, hashed []byte, opts *PSSOptions) (s []byte, err error) ``` SignPSS采用RSASSA-PSS方案計算簽名。注意hashed必須是使用提供給本函數的hash參數對(要簽名的)原始數據進行hash的結果。opts參數可以為nil,此時會使用默認參數。 ## func [VerifyPSS](https://github.com/golang/go/blob/master/src/crypto/rsa/pss.go#L259 "View Source") ``` func VerifyPSS(pub *PublicKey, hash crypto.Hash, hashed []byte, sig []byte, opts *PSSOptions) error ``` VerifyPSS認證一個PSS簽名。hashed是使用提供給本函數的hash參數對(要簽名的)原始數據進行hash的結果。合法的簽名會返回nil,否則表示簽名不合法。opts參數可以為nil,此時會使用默認參數。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看