Java PBEWithMD5AndDES実装アルゴリズムを次に示します。
外部ライブラリを使用せずに、iOS プラットフォーム用のObjective-C で正確に同等のものを探しています。承認されたソリューションは、iOS SDK に含まれるライブラリにのみ依存する必要があります。
以下の Java は、 「bar」をパスフレーズ「foo」で「0WUc+boDvbU=」として暗号化します。
new DesEncrypter("foo").encrypt("bar") == "0WUc+boDvbU="
しかし、obj-c コードはパスフレーズ「foo」を「VRWOhmfj2g8=」として「 bar」を暗号化します。
 NSString* encrypted = [ self encrypt:@"bar"]; == "VRWOhmfj2g8="
私が探しているのは、Java と同じように「bar」を「0WUc+boDvbU=」として暗号化する obj-c 暗号化メソッドです。
Java コード:
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.PBEParameterSpec;
import java.security.spec.AlgorithmParameterSpec;
import java.security.spec.KeySpec;
public class DesEncrypter {
    private Cipher ecipher;
    private Cipher dcipher;
    private byte[] salt = {(byte) 0x10, (byte) 0x1B, (byte) 0x12, (byte) 0x21, (byte) 0xba, (byte) 0x5e,
            (byte) 0x99, (byte) 0x12};
    public DesEncrypter(String passphrase) throws Exception {
        int iterationCount = 2;
        KeySpec keySpec = new PBEKeySpec(passphrase.toCharArray(), salt, iterationCount);
        SecretKey key = SecretKeyFactory.getInstance("PBEWithMD5AndDES").generateSecret(keySpec);
        ecipher = Cipher.getInstance(key.getAlgorithm());
        dcipher = Cipher.getInstance(key.getAlgorithm());
        AlgorithmParameterSpec paramSpec = new PBEParameterSpec(salt, iterationCount);
        ecipher.init(Cipher.ENCRYPT_MODE, key, paramSpec);
        dcipher.init(Cipher.DECRYPT_MODE, key, paramSpec);
    }
    public String encrypt(String str) throws Exception {
        return new BASE64Encoder().encode(ecipher.doFinal(str.getBytes())).trim();
    }
    public String decrypt(String str) throws Exception {
        return new String(dcipher.doFinal(new BASE64Decoder().decodeBuffer(str))).trim();
    }
}
Obj-c コード
- (NSString*) encrypt:(NSString*)encryptValue {
    const void *vplainText;
    size_t plainTextBufferSize = [encryptValue length];
    vplainText = (const void *) [encryptValue UTF8String];
    CCCryptorStatus ccStatus;
    uint8_t *bufferPtr = NULL;
    size_t bufferPtrSize = 0;
    size_t movedBytes = 0;
    bufferPtrSize = (plainTextBufferSize + kCCBlockSizeDES) & ~(kCCBlockSizeDES - 1);
    bufferPtr = malloc( bufferPtrSize * sizeof(uint8_t));
    memset((void *)bufferPtr, 0x0, bufferPtrSize);
    unsigned char salt [] =  {0x10,0x1B,0x12,0x21,0xba,0x5e,0x99,0x12};
    NSString *key = @"foo";
    const void *vkey = (const void *) [key UTF8String];
    ccStatus = CCCrypt(kCCEncrypt,kCCAlgorithmDES,kCCOptionPKCS7Padding,vkey,kCCKeySizeDES,salt,vplainText,
                       plainTextBufferSize,(void *)bufferPtr,bufferPtrSize,&movedBytes);
    NSData *myData = [NSData dataWithBytes:(const void *)bufferPtr length:(NSUInteger)movedBytes];
    NSString *result = [myData base64Encoding];
    return result;
}