Pergunta

I have the ObjC method below and I'd like to call do port it to managed code but have no idea where to start. Can somebody please assist?

- (NSData *)deriveKey
{
    NSData *passphrase = [self.passwordField.stringValue dataUsingEncoding:NSUTF8StringEncoding];
    NSData *salt = [self.saltField.stringValue dataUsingEncoding:NSUTF8StringEncoding];
    NSMutableData *key = [NSMutableData dataWithLength:kCCKeySizeAES256];
    CCKeyDerivationPBKDF(kCCPBKDF2,
                         [passphrase bytes],
                         [passphrase length],
                         [salt bytes],
                         [salt length],
                         kCCPRFHmacAlgSHA256,
                         PBKDFNumberOfRounds,
                         [key mutableBytes],
                         [key length]);
    return key;
}
Foi útil?

Solução

In .NET PKCS#5v2 (which defines PBKDF2) support is available using Rfc2898DeriveBytes. However it does not let you select the hash algorithm.

var salt = new byte [32]; // do not use it empty :)
var key = new Rfc2898DeriveBytes ("passphrase", salt, 1000).GetBytes (length);
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top