나는 암호화/암호 해독 프로그램을 연구 중이다. 나는 AES를 사용하고있다. 내가 고민하는 것은 string password
을 제거하고 AES 세션 키를 만드는 것입니다. 이 AES 세션 키는 데이터를 암호화하고 해독하기 위해 실제로 사용하고자하는 것입니다. 그런 다음 개인 또는 공개 키를 사용하여이 AES 세션 키를 암호화하고 로컬로 저장하십시오 (예 : 목적).AES 세션 키를 암호화하기위한 공용/개인 키
지금까지 코딩 :
// password to encrypt the file
String password = "[email protected]";
// salt is used for encoding
byte[] salt = new byte[8];
SecureRandom secureRandom = new SecureRandom();
secureRandom.nextBytes(salt);
FileOutputStream saltOutFile = new FileOutputStream("salt.enc");
saltOutFile.write(salt);
saltOutFile.close();
SecretKeyFactory factory = SecretKeyFactory
.getInstance("PBKDF2WithHmacSHA1");
KeySpec keySpec = new PBEKeySpec(password.toCharArray(), salt, 65536,
128);
SecretKey secretKey = factory.generateSecret(keySpec);
SecretKey secret = new SecretKeySpec(secretKey.getEncoded(), "AES");
//padding AES encryption
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(Cipher.ENCRYPT_MODE, secret);
AlgorithmParameters params = cipher.getParameters();
// iv adds randomness to the text and just makes the mechanism more
// secure
// used while initializing the cipher
// file to store the iv
FileOutputStream ivOutFile = new FileOutputStream("iv.enc");
byte[] iv = params.getParameterSpec(IvParameterSpec.class).getIV();
ivOutFile.write(iv);
ivOutFile.close();
//file encryption
byte[] input = new byte[64];
int bytesRead;
while ((bytesRead = inFile.read(input)) != -1) {
byte[] output = cipher.update(input, 0, bytesRead);
if (output != null)
outFile.write(output);
}
byte[] output = cipher.doFinal();
if (output != null)
outFile.write(output);
inFile.close();
outFile.flush();
outFile.close();
사람이 변화의 관점에서, 나 좀 도와 주 시겠어요 아래
는 현재 완전히 암호화 및 일반 텍스트 문자열로 데이터를 해독하기 위해 노력하고 있습니다 코딩입니다 생성 된 세션 키에string password
. 그런 다음 공개 또는 개인 키를 사용하여이 세션 키를 암호화하고 로컬 시스템에 저장합니다.
나는 많은 다른 방법을 시도해 왔으며 매번 효과가 없었습니다.
@GiorgiMoniava, 귀하의 회신에 감사드립니다. 나는 공개 키와 개인 키의 작업을 완전히 이해하고있다. 위와 같이 언급 한 이유는 모두 시스템의 사용자에 달려 있기 때문입니다. 이것은 사용자 만이 허용되거나 파일 수준에 대한 액세스 역할을하는 경우 공개 키로 세션 키를 암호화하여 액세스하거나 해독 할 수 있도록하기 때문입니다. 그런 다음 개인 키를 사용하면 여러 명이 액세스 할 수 있고 관련 서명이 필요하면 세션 키를 암호화하는 데 사용됩니다. 그러나 귀하의 회신에 다시 한 번 감사드립니다, 그것은 여전히 감사하겠습니다. – John