IOS를 사용하여 암호화 한 JAVA에서 mp3 파일의 암호를 해독하는 데 문제가 있습니다. 다음은 IOS에서 파일을 암호화에 사용되는 코드입니다 : 아래IOS에서 AES 암호화 (Java에서 암호 해독)
- (NSData *)AES256EncryptWithKey:(NSData *) audioData: (NSString *)key{
// 'key' should be 32 bytes for AES256, will be null-padded otherwise
char keyPtr[kCCKeySizeAES256 + 1]; // room for terminator (unused)
bzero(keyPtr, sizeof(keyPtr)); // fill with zeroes (for padding)
// fetch key data
[key getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding];
NSUInteger dataLength = [audioData length];
//See the doc: For block ciphers, the output size will always be less than or
//equal to the input size plus the size of one block.
//That's why we need to add the size of one block here
size_t bufferSize = dataLength + kCCBlockSizeAES128;
void *buffer = malloc(bufferSize);
size_t numBytesEncrypted = 0;
CCCryptorStatus cryptStatus = CCCrypt(kCCEncrypt, kCCAlgorithmAES128, kCCOptionPKCS7Padding,
keyPtr, kCCKeySizeAES256,
NULL /* initialization vector (optional) */,
[audioData bytes], dataLength, /* input */
buffer, bufferSize, /* output */
&numBytesEncrypted);
if(cryptStatus == kCCSuccess)
{
//the returned NSData takes ownership of the buffer and will free it on deallocation
return [NSData dataWithBytesNoCopy:buffer length:numBytesEncrypted];
}
free(buffer); //free the buffer
return nil;
}
그리고 내가 자바에서 파일을 해독하는 데 사용하고있는 코드입니다, 나는 해독하는 데이 함수를 호출 :
private static final byte[] SALT = {
(byte) 0xA9, (byte) 0x9B, (byte) 0xC8, (byte) 0x32,
(byte) 0x56, (byte) 0x35, (byte) 0xE3, (byte) 0x03
};
private static final int ITERATION_COUNT = 65536;
private static final int KEY_LENGTH = 256;
public static void encryptOrDecrypt(String key, byte[] is, OutputStream os) throws Throwable {
SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
KeySpec spec = new PBEKeySpec(key.toCharArray(), SALT, ITERATION_COUNT, KEY_LENGTH);
SecretKey tmp = factory.generateSecret(spec);
SecretKey secret = new SecretKeySpec(tmp.getEncoded(), "AES");
Cipher ecipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
byte[] iv = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
IvParameterSpec ivspec = new IvParameterSpec(iv);
ecipher.init(Cipher.DECRYPT_MODE, secret, ivspec);
byte[] encrypted = ecipher.doFinal(is);
os.write(encrypted);
os.close();
"3STI :
} 또한 여기
내가 모두에 걸쳐 사용하고있는 열쇠이다 어떤 도움을 크게 감상 할 수
javax.crypto.BadPaddingException: Given final block not properly padded
at com.sun.crypto.provider.SunJCE_f.b(DashoA13*..)....
: 나는 자바 응용 프로그램을 실행할 때 5F2F41608581SO3D8UN346D2E81009THEC7E220RAD9F9C29BPY738956BBE "
나는이 오류가 발생합니다.
감사 마이클
최소한 암호화 보안 전문가가 검토 한 코드의 보안을 신경 쓰는 사람은 내가 한 일이며 수년간 암호를 해왔습니다. 그렇지 않으면, 암호 사용을 시도하는 것을 괴롭히지 마십시오. – zaph