명령 줄을 통해 Mac에서 파일을 암호화하고 해독하는 간단한 내장 방법? 및 암호 해독 할

텍스트 파일을 암호화 및 암호 해독 할 수있는 일종의 명령 줄 도구가 있습니까 (그리고 일종의 암호를 제공).



답변

openssl Mac OS X에 사전 설치되어 제공됩니다.

다음 명령을 사용할 수 있습니다.

# encrypt file.txt to file.enc using 256-bit AES in CBC mode
openssl enc -aes-256-cbc -salt -in file.txt -out file.enc

# the same, only the output is base64 encoded for, e.g., e-mail
openssl enc -aes-256-cbc -a -salt -in file.txt -out file.enc

# decrypt binary file.enc
openssl enc -d -aes-256-cbc -in file.enc -out file.txt

# decrypt base64-encoded version
openssl enc -d -aes-256-cbc -a -in file.enc -out file.txt

( OpenSSL Command-Line HOWTO : 복사 하는 방법은 무엇입니까? )

이 명령은 CBC (Cipher Block Chaining)와 함께 256 비트 AES 암호화를 사용합니다.


답변

이를 위해 쉘 스크립트를 작성했습니다. Mac 또는 Linux에서 사용할 수 있습니다.

#!/bin/bash
#encrypt files with aes-256-cbc cipher using openssl

#encrypt files
if [ $1 == "-e" ];
then
    if [ -f "$2" ];
    then
    openssl aes-256-cbc -a -e -salt -in "$2" -out "$2.aes"
    else
       echo "This file does not exist!"
    fi
#decrypt files
elif [ $1 == "-d" ];
then
    if [ -f "$2" ];
    then
        openssl aes-256-cbc -a -d -salt -in "$2" -out "$2.decrypt"
    else
        echo "This file does not exist!"
    fi
#show help
elif [ $1 == "--help" ];
then
    echo "This software uses openssl for encrypting files with the aes-256-cbc cipher"
    echo "Usage for encrypting: ./encrypt -e [file]"
    echo "Usage for decrypting: ./encrypt -d [file]"
else
    echo "This action does not exist!"
    echo "Use ./encrypt --help to show help."
fi

이것을 chmod + x 파일의 텍스트 파일에 저장하여 실행 가능하게하십시오. 그 후 ./filename –help를 사용하여 정보를 얻으십시오.


답변

Mac OS X에는 암호화 된 컨테이너 파일 (예 : Truecrypt와 유사)을 생성 할 수 있으며, 선택적으로 파일에 배치 된 데이터의 양에 따라 증가 할 수 있습니다. 이를 위해 디스크 유틸리티 를 사용하십시오 .

에서 디스크 유틸리티 를 선택 파일»새로 만들기»빈 디스크 이미지 … 중 하나와 스파 스 이미지 형식을 지원합니다. 암호화로 AES-128 또는 AES-256을 선택하십시오.


명령 행에서 hdiutil프로그램을 통해 동일한 기능을 사용할 수 있습니다 .