encrypt, decrypt - 加密或解密文件
/usr/bin/encrypt -l
/usr/bin/encrypt -a algorithm [-v] [-k key_file | -K key_label [-T token_spec]] [-i input_file] [-o output_file]
/usr/bin/decrypt -l
/usr/bin/decrypt -a algorithm [-v] [-k key_file | -K key_label [-T token_spec]] [-i input_file] [-o output_file]
These utilities encrypt or decrypt the given input file using the algorithm specified.If no input file is specified, input is read from standard input.If no output file is specified, output is printed to standard output.
If the –i and –o options specify the same file, the output is written to a temporary work file in the same file system and then renamed to replace the original input file.
encrypt 的输出文件和 decrypt 的输入文件包含以下信息:
输出格式版本号,采用网络字节顺序的 4 个字节。当前版本是 1。
密钥生成函数中使用的迭代,采用网络字节顺序的 4 个字节。
IV (ivlen bytes)[1].IV data is generated by random bytes equal to one block size.
密钥生成中使用的 Salt 数据(16 字节)。
Cipher text data.
支持以下选项:
指定加密或解密过程中要使用的算法的名称。Note that some weak algorithms may be available for use with the decrypt command only and not for encryption.有关详细信息,请参见“用法”部分的“算法”。
指定输入文件。The default is standard input if –i is not specified.
指定包含用于加密算法的密钥值的文件。每种算法都具有特定的密钥材料要求,如 PKCS#11 规范中所述。如果未指定 –k,encrypt 会使用 getpassphrase(3C) 提示您提供密钥材料。密钥文件的大小确定了密钥长度,从终端设置的口令短语始终用于为密钥长度可变的密码生成长度为 128 位的密钥。
有关生成密钥文件的信息,请参见 pktool(1) 中的 genkey 子命令。Alternatively, dd(8) can be used to read data from the random(4D) device to generate a key file.
指定 PKCS#11 令牌中的对称令牌密钥的标签。
显示系统上可用的算法的列表。此列表可依加密框架的配置而变化。The list is also likely to be different for the encrypt and decrypt commands, as some algorithms such as arcfour and des can no longer be used for encryption, but only for decryption.以位为单位显示密钥大小。
Specify output file.The default is standard output if –o is not specified.If standard output is used without redirecting to a file, the terminal window can appear to hang because the raw encrypted or decrypted data has disrupted the terminal emulation, much like viewing a binary file can do at times.
指定 PKCS#11 令牌,而不使用指定 –K 时的缺省软令牌对象存储。
token_spec 的格式为:
token_name [:manuf_id [:serial_no]]
当令牌标签包含结尾空格时,为方便起见,此选项不要求用户键入这些空格。
Colon separated token identification string.如果任一部分中包含冒号 (:) 文本字符,必须使用反斜杠 (\) 对其进行转义。如果未找到冒号 (:),则将整个字符串(最多 32 个字符)视为令牌标签。如果仅找到一个冒号 (:),则该字符串是令牌标签和生产商。
Display verbose information.See Verbose section.
The supported algorithms are displayed with their minimum and maximum key sizes by the –l option.这些算法由加密框架提供。所支持的每种算法都是 PKCS #11 机制的一个别名,对于特定的算法类型而言,PKCS #11 机制是最常用的也是限制最少的版本。例如,aes 是 CKM_AES_CBC_PAD 的别名,3des 是 CKM_DES3_CBC_PAD 的别名。不支持没有任何填充或 ECB 的算法变体。
这些别名与 –a 选项一起使用,并且区分大小写。
若在加密和解密任务期间未使用 –k 选项,则会提示用户提供口令短语。使用 PKCS #5 中指定的 PBKDF2 算法将该口令短语处理成更安全的密钥。
When a passphrase is used with encrypt and decrypt, the user entered passphrase is turned into an encryption key using the PBKDF2 algorithm as defined in PKCS #5 v2.0.
如果向命令提供输入文件,则屏幕上会显示一个进度条。进度条会在每完成 25% 时使用一个管道符号 (|) 表示。如果输入来自标准输入,每读取 40KB 后都会显示一个句点 (.)。在两种输入方法都完成时,会列显 Done。
以下示例列出了可用的算法:
example$ encrypt -l Algorithm Keysize: Min Max (bits) ----------------------------------- aes 128 256 3des 128 192 camellia 128 256示例 2 Encrypting Using AES
The following example encrypts using AES and prompts for a passphrase:
example$ encrypt -a aes -i myfile.txt -o secretstuff示例 3 对密钥文件使用 AES 加密
以下示例在已创建密钥文件后使用 AES 加密:
example$ pktool genkey keystore=file keytype=aes keylen=128 \ outkey=key example$ encrypt -a aes -k key -i myfile.txt -o secretstuff示例 4 Using Pipes to Provide Encrypted Tape Backup
The following example uses pipes to provide encrypted tape backup:
example$ tar xcf - mydata | encrypt -a aes \ -k ./backup.key | dd of=/dev/rmt/0示例 5 Using Pipes to Restore Tape Backup
The following example uses pipes to restore a tape backup:
example$ decrypt -a aes -k ./backup.key \ -i /dev/rmt/0 | tar zxvf -示例 6 使用 3DES 算法加密输入文件
以下示例使用存储在 des3key 文件中的 192 位密钥加密 inputfile 文件:
example$ encrypt -a 3des -k des3key -i inputfile -o outputfile示例 7 使用 AES 令牌密钥对输入文件进行加密
以下示例使用软令牌密钥库中的 AES 令牌密钥对输入文件进行加密。可使用 pktool(1) 生成 AES 令牌密钥:
example$ encrypt -a aes -K myaeskey \ -T "Sun Software PKCS#11 softtoken" -i inputfile \ -o outputfile示例 8 列出可与 decrypt 结合使用的算法
以下示例列出了可与 decrypt 命令结合使用的算法:
$ decrypt -l Algorithm Keysize: Min Max (bits) ------------------------------------------ aes 128 256 arcfour 8 2048 des 64 64 3des 128 192 camellia 128 256
将返回以下退出值:
成功完成。
出现错误。
有关下列属性的说明,请参见 attributes(7):
|
digest(1)、mac(1)、pktool(1)、getpassphrase(3C)、libpkcs11(3LIB)、attributes(7)、pkcs11_softtoken(7)、dd(8)
Kaliski, B., RFC 2898, PKCS #5: Password-Based Cryptography Specification, Version 2.0, September 2000. https://tools.ietf.org/html/rfc2898
https://www.oasis-open.org/committees/pkcs11/
The –K and –T options were added in Oracle Solaris 11.0.
The encrypt and decrypt commands, and all other options, were added in Solaris 10 3/05.