1

我有下面的 ObjC 方法,我想将它移植到托管代码,但不知道从哪里开始。有人可以帮忙吗?

- (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;
}
4

1 回答 1

1

在 .NET PKCS#5v2(定义PBKDF2)中,可以使用Rfc2898DeriveBytes. 但是,它不允许您选择散列算法。

var salt = new byte [32]; // do not use it empty :)
var key = new Rfc2898DeriveBytes ("passphrase", salt, 1000).GetBytes (length);
于 2013-08-21T13:10:26.650 回答