AES加密和解密 [英] AES Encrypt and Decrypt
问题描述
这是我的.net加密:
public static byte [] AES_Encrypt(byte [] bytesToBeEncrypted,byte [] passwordBytes)
{
byte [] encryptedBytes = null;
byte [] saltBytes = new byte [] {1,2,3,4,5,6,7,8};
使用(MemoryStream ms = new MemoryStream())
{
using(RijndaelManaged AES = new RijndaelManaged())
{
AES.KeySize = 256;
AES.BlockSize = 128;
var key = new Rfc2898DeriveBytes(passwordBytes,saltBytes,1000);
AES.Key = key.GetBytes(AES.KeySize / 8);
AES.IV = key.GetBytes(AES.BlockSize / 8);
AES.Mode = CipherMode.CBC;
使用(var cs = new CryptoStream(ms,AES.CreateEncryptor(),CryptoStreamMode.Write))
{
cs.Write(bytesToBeEncrypted,0,bytesToBeEncrypted.Length) ;
cs.Close();
}
encryptedBytes = ms.ToArray();
}
}
返回encryptedBytes;
}
我需要在swift中解密功能。
我找到了解决方案,这是一个很好的库。
跨平台256位AES加密/解密
此项目包含256位AES加密的实现,适用于所有平台(C#,iOS,Android)。其中一个关键目标是使AES能够在所有平台上实现简单的实现。
支持平台:
iOS,
Android,
Windows(C#)。
https://github.com/Pakhee/Cross-platform-AES-encryption
I write an application by swift, i need AES Encrypt and Decrypt functionality, i received encrypted data from another .Net solution, but i can't find something to do it.
This is my .net Encryption:
public static byte[] AES_Encrypt(byte[] bytesToBeEncrypted, byte[] passwordBytes)
{
byte[] encryptedBytes = null;
byte[] saltBytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
using (MemoryStream ms = new MemoryStream())
{
using (RijndaelManaged AES = new RijndaelManaged())
{
AES.KeySize = 256;
AES.BlockSize = 128;
var key = new Rfc2898DeriveBytes(passwordBytes, saltBytes, 1000);
AES.Key = key.GetBytes(AES.KeySize / 8);
AES.IV = key.GetBytes(AES.BlockSize / 8);
AES.Mode = CipherMode.CBC;
using (var cs = new CryptoStream(ms, AES.CreateEncryptor(), CryptoStreamMode.Write))
{
cs.Write(bytesToBeEncrypted, 0, bytesToBeEncrypted.Length);
cs.Close();
}
encryptedBytes = ms.ToArray();
}
}
return encryptedBytes;
}
I need to decrypt function in swift.
I found the solution, it is a good library.
Cross platform 256bit AES encryption / decryption.
This project contains the implementation of 256 bit AES encryption which works on all the platforms (C#, iOS, Android). One of the key objective is to make AES work on all the platforms with simple implementation.
Platforms Supported: iOS , Android , Windows (C#).
https://github.com/Pakhee/Cross-platform-AES-encryption
这篇关于AES加密和解密的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!