XU XUv0.8.8
EN

API

#crypto/rsa

import: #crypto/rsa

counts: 5 函数, 1 方法, 2 类型, 4 常量, 0 方法集

PKCS#1 v1.5 加密与签名。无 OAEP/PSS。

const sha1

XuAPI
pub const sha1 = 3

用途

公开常量 `sha1`。 值为 `3`

参数

无

const sha256

XuAPI
pub const sha256 = 5

用途

公开常量 `sha256`。 值为 `5`

参数

无

const sha384

XuAPI
pub const sha384 = 6

用途

公开常量 `sha384`。 值为 `6`

参数

无

const sha512

XuAPI
pub const sha512 = 7

用途

公开常量 `sha512`。 值为 `7`

参数

无

struct PublicKey

XuAPI
pub struct PublicKey {
    pub n big.Int
    pub e int
}

用途

公开结构体 `PublicKey`。

参数

n big.Int
数量、长度或上限
e int
字段(int)

struct PrivateKey

XuAPI
pub struct PrivateKey {
    pub public PublicKey
    pub d big.Int
    pub p big.Int
    pub q big.Int
}

用途

公开结构体 `PrivateKey`。

参数

public PublicKey
字段(PublicKey)
d big.Int
字段(big.Int)
p big.Int
字段(big.Int)
q big.Int
字段(big.Int)

(&PublicKey) size

XuAPI
pub fn (pk &PublicKey) size() int

用途

`&PublicKey` 上的方法:返回尺寸。

参数

pk &PublicKey
接收者 &PublicKey(借用)

返回

int — 该类型的值

encrypt_pkcs1v15

XuAPI
pub fn encrypt_pkcs1v15(pk &PublicKey, msg &string) string

用途

加密pkcs1v15。失败时 throw。

参数

pk &PublicKey
pk(借用,调用方仍持有;类型 &PublicKey)
msg &string
消息(借用,调用方仍持有;类型 &string)

返回

string — 结果字符串

decrypt_pkcs1v15

XuAPI
pub fn decrypt_pkcs1v15(priv &PrivateKey, ciphertext &string) string

用途

解密pkcs1v15。失败时 throw。

参数

priv &PrivateKey
priv(借用,调用方仍持有;类型 &PrivateKey)
ciphertext &string
ciphertext(借用,调用方仍持有;类型 &string)

返回

string — 结果字符串

sign_pkcs1v15

XuAPI
pub fn sign_pkcs1v15(priv &PrivateKey, hash int, hashed &string) string

用途

符号pkcs1v15。失败时 throw。

参数

priv &PrivateKey
priv(借用,调用方仍持有;类型 &PrivateKey)
hash int
hash(int)
hashed &string
hashed(借用,调用方仍持有;类型 &string)

返回

string — 结果字符串

verify_pkcs1v15

XuAPI
pub fn verify_pkcs1v15(pk &PublicKey, hash int, hashed &string, sig &string) int

用途

验签pkcs1v15。失败时 throw。

参数

pk &PublicKey
pk(借用,调用方仍持有;类型 &PublicKey)
hash int
hash(int)
hashed &string
hashed(借用,调用方仍持有;类型 &string)
sig &string
sig(借用,调用方仍持有;类型 &string)

返回

int — 该类型的值

generate_key

XuAPI
pub fn generate_key(bits int) PrivateKey

用途

生成键。失败时 throw。

参数

bits int
比特数(int)

返回

PrivateKey — 该类型的值