跳转到内容
View in the app

A better way to browse. Learn more.

彼岸论坛

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
欢迎抵达彼岸 彼岸花开 此处谁在 -彼岸论坛

[Rust] rust 写代码真的很复杂

发表于
```rust
use aes_gcm::{aead::{Aead, AeadCore, KeyInit, OsRng}, Aes256Gcm, AesGcm};
use aes_gcm::aead::consts::U12;
use aes_gcm::aead::Nonce;
use aes_gcm::aes::Aes256;

// aes-gcm = "0.10.3"

#[test]
fn test_3_aes256_cbc() {
// 生成一个随机的 AES256-GCM 加密密钥 key 。
// The encryption key can be generated randomly:
let key = Aes256Gcm::generate_key(OsRng);

// 使用生成的密钥 key 创建 AES256-GCM 加密器 cipher ,然后生成一个 96 位长度的随机 nonce nonce 。
// 使用 cipher 对 "plaintext message" 进行加密得到 ciphertext ,然后再对 ciphertext 进行解密得到 plaintext 。
// 最后使用 assert_eq! 宏来验证解密后的 plaintext 是否与原始消息相同。
let cipher: AesGcm<Aes256, U12> = Aes256Gcm::new(&key);
// 生成随机 nonce ( 96 bits )
// let nonce = GenericArray::from_slice(&Aes256Gcm::generate_nonce(&mut OsRng));
// let nonce: &GenericArray<u8, <Aes256Gcm as Aead>::NonceSize> = GenericArray::from_slice(&Aes256Gcm::generate_nonce(&mut OsRng));
// let nonce: GenericArray<u8, <Aes256Gcm as Aead>::NonceSize> = ...;
let nonce: Nonce<Aes256Gcm> = Aes256Gcm::generate_nonce(&mut OsRng); // 96-bits; unique per message

// 将明文消息作为字节数组传递给 encrypt 函数。
let plaintext: &[u8] = b"plaintext message";
let ciphertext = cipher.encrypt(&nonce, plaintext).unwrap();
let plaintext = cipher.decrypt(&nonce, ciphertext.as_ref()).unwrap();

assert_eq!(&plaintext, b"plaintext message");
}


```

let plaintext: &[u8] = b"plaintext message";

这一行代码,要自己将手动推导的 &[u8;17] 固定长度数组,,修改为可变数组。。

以及一些其他的,,整个代码才可以运行

Featured Replies

没有可显示的帖子

创建帐户或登录来提出意见

Account

导航

搜索

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.