7 ответов:
Это лучший ответ на ваш вопрос от google: http://tombuntu.com/index.php/2007/12/12/simple-file-encryption-with-openssl/
шифровать:
openssl aes-256-cbc -a -salt -in secrets.txt -out secrets.txt.encрасшифровать:
openssl aes-256-cbc -d -a -in secrets.txt.enc -out secrets.txt.newно это вообще не использует инфраструктуру открытых ключей, поэтому немного похоже на забивание гвоздя отверткой : -)
Короткий Ответ:
вы, вероятно, хотите использовать
gpgвместоopensslпосмотрим "Дополнительные Примечания" в конце этого ответа. Но чтобы ответить на вопрос, используяopenssl:Шифровать:
openssl enc -aes-256-cbc -in un_encrypted.data -out encrypted.dataРасшифровать:
openssl enc -d -aes-256-cbc -in encrypted.data -out un_encrypted.dataПримечание: вам будет предложено ввести пароль для шифрования или дешифрования.
долго Ответ:
ваш лучший источник информации для
openssl encвероятно, будет:https://www.openssl.org/docs/apps/enc.htmlКомандная строка:
openssl encимеет следующий вид:openssl enc -ciphername [-in filename] [-out filename] [-pass arg] [-e] [-d] [-a/-base64] [-A] [-k password] [-kfile filename] [-K key] [-iv IV] [-S salt] [-salt] [-nosalt] [-z] [-md] [-p] [-P] [-bufsize number] [-nopad] [-debug] [-none] [-engine id]объяснение наиболее полезных параметров в отношении вашего вопроса:
-e Encrypt the input data: this is the default. -d Decrypt the input data. -k <password> Only use this if you want to pass the password as an argument. Usually you can leave this out and you will be prompted for a password. The password is used to derive the actual key which is used to encrypt your data. Using this parameter is typically not considered secure because your password appears in plain-text on the command line and will likely be recorded in bash history. -kfile <filename> Read the password from the first line of <filename> instead of from the command line as above. -a base64 process the data. This means that if encryption is taking place the data is base64 encoded after encryption. If decryption is set then the input data is base64 decoded before being decrypted. You likely DON'T need to use this. This will likely increase the file size for non-text data. Only use this if you need to send data in the form of text format via email etc. -salt To use a salt (randomly generated) when encrypting. You always want to use a salt while encrypting. This parameter is actually redundant because a salt is used whether you use this or not which is why it was not used in the "Short Answer" above! -K key The actual key to use: this must be represented as a string comprised only of hex digits. If only the key is specified, the IV must additionally be specified using the -iv option. When both a key and a password are specified, the key given with the -K option will be used and the IV generated from the password will be taken. It probably does not make much sense to specify both key and password. -iv IV The actual IV to use: this must be represented as a string comprised only of hex digits. When only the key is specified using the -K option, the IV must explicitly be defined. When a password is being specified using one of the other options, the IV is generated from this password.
Дополнительная Информация:
хотя вы специально спросили об OpenSSL, вы можете рассмотреть возможность использования GPG вместо этого в целях шифрования на основе этой статьи OpenSSL vs GPG для шифрования резервных копий за пределами сайта?
чтобы использовать GPG, чтобы сделать то же самое, вы должны использовать следующие команды:
Шифровать:
gpg --output encrypted.data --symmetric --cipher-algo AES256 un_encrypted.dataРасшифровать:
gpg --output un_encrypted.data --decrypt encrypted.dataПримечание: вам будет предложено ввести пароль для шифрования или дешифрования.
шифровать:
openssl enc -in infile.txt -out encrypted.dat -e -aes256 -k symmetrickeyрасшифровать:
openssl enc -in encrypted.dat -out outfile.txt -d -aes256 -k symmetrickeyдля получения дополнительной информации см.
openssl(1)docs.
Шифровать:
$ openssl bf < arquivo.txt > arquivo.txt.bfРасшифровать:
$ openssl bf -d < arquivo.txt.bf > arquivo.txtbf = = = Blowfish в режиме CBC
обновление с помощью случайного открытого ключа.
Encypt:
openssl enc -aes-256-cbc -a -salt -in {raw data} -out {encrypted data} -pass file:{random key}расшифровать:
openssl enc -d -aes-256-cbc -in {ciphered data} -out {raw data}у меня есть полный учебник по этому вопросу в http://bigthinkingapplied.com/key-based-encryption-using-openssl/
есть программа с открытым исходным кодом, которую я нахожу в интернете, она использует openssl для шифрования и расшифровки файлов. Он делает это с помощью одного пароля. Самое замечательное в этом скрипте с открытым исходным кодом заключается в том, что он удаляет исходный незашифрованный файл, измельчая файл. Но опасная вещь о том, как только оригинальный незашифрованный файл ушел, вы должны убедиться, что вы помните свой пароль, иначе они не будут другим способом расшифровать ваш файл.
здесь ссылка на github
https://github.com/EgbieAnderson1/linux_file_encryptor/blob/master/file_encrypt.py
пример вызова PHP через Bash:
IV='c2FtcGxlLWFlcy1pdjEyMw==' KEY='Twsn8eh2w2HbVCF5zKArlY+Mv5ZwVyaGlk5QkeoSlmc=' INPUT=123456789023456 ENCRYPTED=$(php -r "print(openssl_encrypt('$INPUT','aes-256-ctr',base64_decode('$KEY'),OPENSSL_ZERO_PADDING,base64_decode('$IV')));") echo '$ENCRYPTED='$ENCRYPTED DECRYPTED=$(php -r "print(openssl_decrypt('$ENCRYPTED','aes-256-ctr',base64_decode('$KEY'),OPENSSL_ZERO_PADDING,base64_decode('$IV')));") echo '$DECRYPTED='$DECRYPTEDэтот выходы:
$ENCRYPTED=nzRi252dayEsGXZOTPXW $DECRYPTED=123456789023456вы также можете использовать PHP
openssl_pbkdf2функция для безопасного преобразования парольной фразы в ключ.
Comments