使用私钥加密/解密

发布于 2024-11-15 22:50:08 字数 489 浏览 3 评论 0原文

我想在我拥有的一些 Flash/PHP 应用程序中实现一些安全性。

我有一些与 PHP 文件通信的 Flash 应用程序,并且 PHP 将数据作为 get 字符串发送(例如: name=John&sname=Doe&age=24&balance=12.4 )。我希望它发送包含这些值的单个变量(例如:flashvar=jr9afgaw9-fg90agfawf7gw),而不是所有这些变量,这样 Flash 就会解密字符串并获取 真实且有用的变量。

我想使用私钥对其进行加密,并使用相同的私钥在 Flash 中对其进行解密。如果有人想要解码 PHP 发送的消息,他必须反编译 Flash 文件并找到我在 Flash 中使用的私钥来解码消息,然后对其进行解码。

我在这里发布的原因是因为我想使用一种仅允许使用私钥进行加密/解密的加密算法。

我是密码学领域的新手,我想对此提出一些建议。

谢谢你!

I would like to implement some security in some of the Flash/PHP applications that I have.

I have some Flash apps that communicate with PHP files, and the PHP is sending the data as get string ( e.g.: name=John&sname=Doe&age=24&balance=12.4 ). Instead of all these variables, I would like it to send a single variable ( e.g.: flashvar=jr9afgaw9-fg90agfawf7gw ) that would contain those values, so then Flash would decrypt the string and get the real and useful vars.

I want to encrypt this using a private key and use the same private key to decrypt this inside Flash. If someone would want to decode the message PHP sends, he would have to decompile the flash file and find the private key I'm using in Flash to decode the message and then decode it.

The reason I posted here is because I want to use an encryption algorithm that allows only the use of a private key for encryption/decryption.

I'm new in the cryptography field and I'd like some suggestions for this.

Thank you!

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

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

发布评论

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

评论(3

所谓喜欢 2024-11-22 22:50:08

“共享私钥”被称为对称密钥。目前使用的标准对称算法是 AES。我不知道 php 或 flash 是否有能力使用 AES(Google 有),但如果有,您可以在代码中硬编码 AES 密钥,并使用它来加密和解密数据。然而,对密钥进行硬编码是非常糟糕的加密技术,只不过是混淆而已。

另一件需要记住的事情是您正在使用的密码模式。密码块链接 (CBC) 需要使用初始化向量(有点像哈希的盐),因此使用相同密钥但不同 IV 加密的两个相同值将导致不同的密文。 ECB 不需要初始化向量,但安全性较差。根据您的需求,我会选择欧洲央行,这样您就不必担心静脉注射。

谷歌是一个非常好的查找​​信息的方式,你应该使用它。

A "shared private key" is refered to as a symmetric key. The standard symmetric algorithm in use today is AES. I have no idea if php, or flash, have the capability of using AES (Google does), but if they do, you could hard code an AES key in your code and use it to encrypt and decrypt data. However, hard coding a key is very bad cryptography and is little more than obfuscation.

Another thing to keep in mind is the cipher mode you are using. Cipher Block Chaining (CBC) requires the use of an initialization vector (sort of like a salt for a hash), so two of the same values encrypted with the same key, but different IV, will result in differen cipher text. ECB does not need an initialization vector, but is less secure. For your needs I would go with ECB so you dont have to worry about an IV.

Google is a very good way of finding information, you should use it.

情深已缘浅 2024-11-22 22:50:08

经过快速搜索,我发现 ActionScript 3 通过 ASCrypt3 库支持加密。据该网站称,支持 AES Rijndael。

使用 mcrypt 扩展在 PHP 中也支持 Rijndael。这是一个非常好的示例取自手册

$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$key = "This is a very secret key";
$text = "Meet me at 11 o'clock behind the monument.";
echo strlen($text) . "\n";

$crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_ECB, $iv);
echo strlen($crypttext) . "\n";

After a quick search, I saw that ActionScript 3 has support for encryption throught ASCrypt3 library. According to the website, AES Rijndael is supported.

Rijndael is also supported in PHP using the mcrypt extension. Here's a pretty good example taken from the manual:

$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$key = "This is a very secret key";
$text = "Meet me at 11 o'clock behind the monument.";
echo strlen($text) . "\n";

$crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_ECB, $iv);
echo strlen($crypttext) . "\n";
樱花细雨 2024-11-22 22:50:08

如果您想加密数据,我会使用 ASCrypt3o 库。
它工作得很好并且支持多种类型的加密。
您可以在此处单击密钥选项卡查看其演示。

If You want to encrypt data I would go with the ASCrypt3o library.

It works very well and supports multiple types of encryption.
You can see a demo of it here click on the secret key tab.

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