繁体   English   中英

CCKeyDerivationPBKDF如何转换为Xamarin.iOS?

[英]How can CCKeyDerivationPBKDF be converted to Xamarin.iOS?

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

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

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

var salt = new byte [32]; // do not use it empty :)
var key = new Rfc2898DeriveBytes ("passphrase", salt, 1000).GetBytes (length);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM