obj-c コードで暗号化されたファイルがあります。
NSMutableData *fileData = [NSMutableData new];
// Get file data.
[[self encrypt::fileData WithKey:@"SOME_KEY"]]
- (NSMutableData*) encrypt:(NSMutableData*)data WithKey: (NSString *) key
{
// 'key' should be 32 bytes for AES256, will be null-padded otherwise
char keyBuffer[kCCKeySizeAES128+1]; // room for terminator (unused)
bzero( keyBuffer, sizeof(keyBuffer) ); // fill with zeroes (for padding)
[key getCString: keyBuffer maxLength: sizeof(keyBuffer) encoding: NSUTF8StringEncoding];
// encrypts in-place, since this is a mutable data object
size_t numBytesEncrypted = 0;
size_t returnLength = ([data length] + kCCKeySizeAES256) & ~(kCCKeySizeAES256 - 1);
char* returnBuffer = malloc(returnLength * sizeof(uint8_t) );
CCCryptorStatus result = CCCrypt(kCCEncrypt, kCCAlgorithmAES128 , kCCOptionPKCS7Padding | kCCOptionECBMode,
keyBuffer, kCCKeySizeAES128, nil,
[data bytes], [data length],
returnBuffer, returnLength,
&numBytesEncrypted);
if(result == kCCSuccess)
return [NSMutableData dataWithBytes:returnBuffer length:numBytesEncrypted];
else
return nil;
}
このファイルをjavaで読みたいです。やっています
SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
// What is salt ??
KeySpec spec = new PBEKeySpec("SOME_KEY", salt, 65536, 256);
SecretKey tmp = factory.generateSecret(spec);
SecretKey secret = new SecretKeySpec(tmp.getEncoded(), "AES");
Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
cipher.init(Cipher.DECRYPT_MODE, secret, new IvParameterSpec(iv));
String plaintext = new String(cipher.doFinal(ciphertext), "UTF-8");
System.out.println(plaintext);
私はobj-cについて何も知りません。私はこれを成し遂げることができると思いますか?ありがとうございました。