Perl 6中的AES加密?

che*_*nyf 11 perl6 raku

我正在尝试将用Python编写的模块转换为Perl 6,我发现在Perl 6中没有AES方法:

from Cryptodome.Cipher import AES
import base64

def aes(text, key):
    pad = 16 - len(text) % 16
    text = text + bytearray([pad] * pad)
    encryptor = AES.new(key, 2, b"0102030405060708")
    ciphertext = encryptor.encrypt(text)
    return base64.b64encode(ciphertext)
Run Code Online (Sandbox Code Playgroud)

在Perl 6中是否有任何模块编写实现AES方法?

Jon*_*ton 13

OpenSSL模块似乎提供了对各种AES密码的访问.这取决于openssl库是否可用(尽管在Windows上我相信它会将DLL作为模块安装过程的一部分下载).

使用installed(zef install OpenSSL),可以:

use OpenSSL::CryptTools;
Run Code Online (Sandbox Code Playgroud)

然后使用encrypt/ decrypt:

# Fake IV and key
my $iv = ('0' x 16).encode;
my $key = ('xy' x 16).encode;

# Encrypt.
my $ciphertext = encrypt("asdf".encode, :aes256, :$iv, :$key);
say $ciphertext;

# Decrypt.
say decrypt($ciphertext, :aes256, :$iv, :$key).decode;
Run Code Online (Sandbox Code Playgroud)

有关更多示例,请参阅这些测试