相当于C+中的Rfc2898DeriveBytes+;不使用CLR C++中的RCFC998派生字节是什么,不使用CLR。C#样本如下所示 string clearText="text to sign"; string EncryptionKey = "secret"; byte[] clearBytes = Encoding.UTF8.GetBytes(clearText); using (Aes encryptor = Aes.Create()) { Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { 0x48, 0x71, 0x21, 0x6d, 0x21, 0x4c, 0x61, 0x62, 0x72, 0x62, 0x61, 0x62, 0x72 }); 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, 0, clearBytes.Length); cs.Close(); } clearText = Convert.ToBase64String(ms.ToArray()); } }

相当于C+中的Rfc2898DeriveBytes+;不使用CLR C++中的RCFC998派生字节是什么,不使用CLR。C#样本如下所示 string clearText="text to sign"; string EncryptionKey = "secret"; byte[] clearBytes = Encoding.UTF8.GetBytes(clearText); using (Aes encryptor = Aes.Create()) { Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { 0x48, 0x71, 0x21, 0x6d, 0x21, 0x4c, 0x61, 0x62, 0x72, 0x62, 0x61, 0x62, 0x72 }); 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, 0, clearBytes.Length); cs.Close(); } clearText = Convert.ToBase64String(ms.ToArray()); } },c++,cryptography,pbkdf2,C++,Cryptography,Pbkdf2,您可以在OpenSSL中使用PKCS5\u PBKDF2\u HMAC 这两种功能都是功能性的,可以互换使用 更新: 下面是一个示例代码,用于在C和OpenSSL中生成类似的密钥 C#side: public static void Main() { string EncryptionKey = "secret"; Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { 0x48, 0

您可以在OpenSSL中使用
PKCS5\u PBKDF2\u HMAC

这两种功能都是功能性的,可以互换使用

更新:

下面是一个示例代码,用于在
C
OpenSSL
中生成类似的密钥

C#
side:

public static void Main()
{
    string EncryptionKey = "secret";
    Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { 0x48, 0x71, 0x21, 0x6d, 0x21, 0x4c, 0x61, 0x62, 0x72, 0x62, 0x61, 0x62, 0x72 }, 1000);
    Console.WriteLine("[{0}]", string.Join(", ", pdb.GetBytes(32)));
    Console.WriteLine("[{0}]", string.Join(", ", pdb.GetBytes(16)));
}
#include <openssl/evp.h>
#include <string.h>
#include <stdlib.h>

int main(){
        char secret[] = "secret";
        unsigned char buf[48] = {0,};
        int size = 48;
        unsigned char salt[] = { 0x48, 0x71, 0x21, 0x6d, 0x21, 0x4c, 0x61, 0x62, 0x72, 0x62, 0x61, 0x62, 0x72 };
        PKCS5_PBKDF2_HMAC(secret, strlen(secret), salt, sizeof(salt), 1000, EVP_sha1(), size, buf);
        for (int i = 0; i < size; i++)
                printf("%d ", buf[i]);
        return 0;
}
OpenSSL
side:

public static void Main()
{
    string EncryptionKey = "secret";
    Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { 0x48, 0x71, 0x21, 0x6d, 0x21, 0x4c, 0x61, 0x62, 0x72, 0x62, 0x61, 0x62, 0x72 }, 1000);
    Console.WriteLine("[{0}]", string.Join(", ", pdb.GetBytes(32)));
    Console.WriteLine("[{0}]", string.Join(", ", pdb.GetBytes(16)));
}
#include <openssl/evp.h>
#include <string.h>
#include <stdlib.h>

int main(){
        char secret[] = "secret";
        unsigned char buf[48] = {0,};
        int size = 48;
        unsigned char salt[] = { 0x48, 0x71, 0x21, 0x6d, 0x21, 0x4c, 0x61, 0x62, 0x72, 0x62, 0x61, 0x62, 0x72 };
        PKCS5_PBKDF2_HMAC(secret, strlen(secret), salt, sizeof(salt), 1000, EVP_sha1(), size, buf);
        for (int i = 0; i < size; i++)
                printf("%d ", buf[i]);
        return 0;
}
#包括
#包括
#包括
int main(){
char secret[]=“secret”;
无符号字符buf[48]={0,};
int size=48;
无符号字符盐[]={0x48、0x71、0x21、0x6d、0x21、0x4c、0x61、0x62、0x72、0x62、0x61、0x62、0x72};
PKCS5_PBKDF2_HMAC(秘密,斯特伦(秘密),盐,sizeof(盐),1000,EVP_sha1(),尺寸,buf);
对于(int i=0;i

请记住,在这些代码中,迭代次数仅为1000次,至少使用100000次甚至1000000次。

。也可以看到标签。谢谢分享链接。。。大多数代码实际上不是在C++中,所以你评论的是没有足够的替代C++实现来选择吗?也许社区应该为你找到更多的?谢谢你的回复。。。我们尝试了你的共享方法。C++中的加密值(Cyfter文本)在C代码中没有被解码。我们用C++代码加密文本,用C来解密文本。@ RJ最好自己解决问题。写这篇文章只花了几分钟。但我会帮你更新的。