大佬教程收集整理的这篇文章主要介绍了Objective#C等效代码的C#代码,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
internal static class Common { static String encryptionKey = "0C61L2FSL2F3E7X8E9T1L2F3E4O5"; static byte[] salt = new byte[] {0x49,0x76,0x61,0x6e,0x20,0x4d,0x65,0x64,0x76}; internal static String Encrypt(String clearText) { byte[] clearBytes = Encoding.Unicode.GetBytes(clearText); using (Aes encryptor = Aes.Create()) { Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(encryptionKey,salt); encryptor.Key = pdb.GetBytes(32); encryptor.IV = pdb.GetBytes(16); using (MemoryStream ms = new MemoryStream()) { using (CryptoStream cs = new CryptoStream(ms,encryptor.CreateEncryptor(),CryptoStreAMMode.WritE)) { cs.Write(clearBytes,clearBytes.Length); cs.Close(); } clearText = Convert.ToBase64String(ms.ToArray()); } } return clearText; } }
以上代码用于加密.我试图获得RFC2898derivebytes的等效函数.
-(void)doEncryption { NSString *url = @"www.google.com"; const char salt[] = {0x49,0x76}; NSData *saltData =[NSData dataWithBytes:salt length:13]; NSData* myPassData = [EncryptionKey dataUsingEncoding:NSUTF8StringEncoding]; unsigned char keY[32]; CCKeyDerivationPBKDF(kCCPBKDF2,myPassData.bytes,myPassData.length,saltData.bytes,saltData.length,kCCPRFHmacAlgSHA1,1000,key,32); unsigned char InitialVector[16]; CCKeyDerivationPBKDF(kCCPBKDF2,InitialVector,16); NSString *Aeskey = [[NSString alloc] initWithBytes:key length:sizeof(key) encoding:NSUnicodeStringEncoding]; NSLog(@"Key AES : %@",Aeskey); NSString *AesIV = [[NSString alloc] initWithBytes:InitialVector length:sizeof(key) encoding:NSASCIIStringEncoding]; NSString *encryptedString = [AESCrypt encrypt:url password:Aeskey andIV:AesIV]; [self doDecryption:encryptedString withKey:nil]; }
以上是大佬教程为你收集整理的Objective#C等效代码的C#代码全部内容,希望文章能够帮你解决Objective#C等效代码的C#代码所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。