将 Symbian 描述符形式的非常大的整数转换为无符号字符*

发布于 2024-11-07 03:46:58 字数 547 浏览 0 评论 0原文

我们正在尝试使用 Open C/C++ 库 (rsa.h) 和“RSA_public_encrypt”方法在 Symbian 中实现 RSA 加密:

buffSize = RSA_public_encrypt(maxSize, (unsigned char *) plainkey, (unsigned char * ) cipherkey, rsa, RSA_NO_PADDING);

我们使用自己的指数和模数创建了一个公钥,并将其放入“rsa”对象中。 我们要加密的纯文本是一个以字符串形式接收的非常大的整数(作为 Symbian 描述符)。

但是,纯文本应作为“unsigned char*”提供给加密方法。 如何将描述符(纯文本)转换为“unsigned char*”,以便加密方法将我们的纯文本解释为一个非常大的整数。 或者对于那些不熟悉 Symbian 描述符的人:如何将纯文本从常规字符串 (char *) 转换为加密解释为非常大的整数的值。

我们已经尝试通过多种方式提供纯文本,但加密文本并不是应有的样子 (我们将此与我们验证正确的其他平台上的结果进行比较)。

非常感谢任何帮助。

We're trying to implement RSA encryption in Symbian using the Open C/C++ library (rsa.h), and the 'RSA_public_encrypt' method:

buffSize = RSA_public_encrypt(maxSize, (unsigned char *) plainkey, (unsigned char *) cipherkey, rsa, RSA_NO_PADDING);

We created a public key with our own exponent and modulus and put that in the 'rsa'-object.
Our plain text to be encrypted is a very large integer received in string form (so as a Symbian descriptor).

However, the plain text should be provided as an 'unsigned char*' to the encryption method.
How can I transform the descriptor (plain text) to an 'unsigned char*' so that the encryption method interprets our plain text as a very large integer.
Or for those not familiar with Symbian descriptors: how can I transform the plain text from a regular string (char *) to a value that the encryption interprets as a very large integer.

We already tried to provide the plain text in several ways, but the encryption text wasn't what it should have been
(we compared this with results on other platforms which we verified was correct).

Any help is greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

〗斷ホ乔殘χμё〖 2024-11-14 03:46:58

您必须分配(malloc)plainkey 和cipherkey 变量,并使用lstrcpy 或类似的东西将未加密的纯文本字符串复制到cipherkey,以便使该函数正常工作。

plainkey = malloc(PLAINKEY_SIZE);
cipherkey = malloc(CIPHERKEY_SIZE);
lstrcpy(plainkey, "12345...");
buffSize = RSA_public_encrypt(maxSize, plainkey, cipherkey, rsa, RSA_NO_PADDING);

您还可以使用无符号字符数组:

unsigned char plainkey[PLAINKEY_SIZE] = "12345...";
unsigned char plainkey[CIPHERKEY_SIZE];
buffSize = RSA_public_encrypt(maxSize, plainkey, cipherkey, rsa, RSA_NO_PADDING);

You have to allocate (malloc) the plainkey and cipherkey variables and copy the unencrypted plain text string to cipherkey using lstrcpy or something similar in order to make this function work.

plainkey = malloc(PLAINKEY_SIZE);
cipherkey = malloc(CIPHERKEY_SIZE);
lstrcpy(plainkey, "12345...");
buffSize = RSA_public_encrypt(maxSize, plainkey, cipherkey, rsa, RSA_NO_PADDING);

you can also use unsigned char arrays:

unsigned char plainkey[PLAINKEY_SIZE] = "12345...";
unsigned char plainkey[CIPHERKEY_SIZE];
buffSize = RSA_public_encrypt(maxSize, plainkey, cipherkey, rsa, RSA_NO_PADDING);
二智少女猫性小仙女 2024-11-14 03:46:58

RSA_public_encrypt 的第一个参数是 flen,第二个参数是 from,即它将加密 flen 字节中的 来自

假设您有一个要加密的 TDesC8 描述符 source,请像这样调用该函数:

 RSA_public_encrypt(source.Length(), source.Ptr(), ... 

The first argument to RSA_public_encrypt is flen and the second is from i.e. it will encrypt flen bytess from from.

Assuming you have a TDesC8 descriptor source you want to encrypt, call the function like this:

 RSA_public_encrypt(source.Length(), source.Ptr(), ... 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文