XU XUv0.8.8
EN

API

#crypto/aes

import: #crypto/aes

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

AES-128/192/256 单块。CBC/CTR/GCM 见 crypto/cipher。

const block_size

XuAPI
pub const block_size = 16

用途

公开常量 `block_size`。 值为 `16`

参数

无

struct Cipher

XuAPI
pub struct Cipher {
    pub nr int
    pub rk []int
    pub sbox []int
    pub inv []int
    pub te []int
    pub td []int
    pub erk []int
    pub drk []int
    pub hw_accel bool
    pub rk_bytes string
    pub drk_bytes string
}

用途

公开结构体 `Cipher`。

参数

nr int
字段(int)
rk []int
字段([]int)
sbox []int
字段([]int)
inv []int
字段([]int)
te []int
字段([]int)
td []int
字段([]int)
erk []int
字段([]int)
drk []int
字段([]int)
hw_accel bool
字段(bool)
rk_bytes string
字段(string)
drk_bytes string
字段(string)

new_cipher

XuAPI
pub fn new_cipher(key &string) Cipher

用途

构造 cipher。失败时 throw。

参数

key &string
键(借用,调用方仍持有;类型 &string)

返回

Cipher — 该类型的值

(&Cipher) block_size

XuAPI
pub fn (c &Cipher) block_size() int

用途

`&Cipher` 上的方法:块尺寸。

参数

c &Cipher
接收者 &Cipher(借用)

返回

int — 该类型的值

(&Cipher) encrypt

XuAPI
pub fn (c &Cipher) encrypt(src &string) string

用途

`&Cipher` 上的方法:加密。失败时 throw。

参数

c &Cipher
接收者 &Cipher(借用)
src &string
源数据(借用,调用方仍持有;类型 &string)

返回

string — 结果字符串

(&Cipher) encrypt_block

XuAPI
pub fn (c &Cipher) encrypt_block(dst &mut []int, src &[]int) bool

用途

`&Cipher` 上的方法:加密块。失败时 throw。

参数

c &Cipher
接收者 &Cipher(借用)
dst &mut []int
目标(独占借用;类型 &mut []int)
src &[]int
源数据(借用,调用方仍持有;类型 &[]int)

返回

bool — 是否成立

(&Cipher) decrypt

XuAPI
pub fn (c &Cipher) decrypt(src &string) string

用途

`&Cipher` 上的方法:解密。失败时 throw。

参数

c &Cipher
接收者 &Cipher(借用)
src &string
源数据(借用,调用方仍持有;类型 &string)

返回

string — 结果字符串

(&Cipher) decrypt_block

XuAPI
pub fn (c &Cipher) decrypt_block(dst &mut []int, src &[]int) bool

用途

`&Cipher` 上的方法:解密块。失败时 throw。

参数

c &Cipher
接收者 &Cipher(借用)
dst &mut []int
目标(独占借用;类型 &mut []int)
src &[]int
源数据(借用,调用方仍持有;类型 &[]int)

返回

bool — 是否成立