我想用 php 加密我的用户 ID,然后将它们发送到 javascript。并用 JavaScript 解密它们。
不同语言之间有没有通用的加密和解密方法?
我正在使用节点js。Nodejs 有服务器端 JavaScript。实际上它是服务器端解密。但它是JavaScript。
我已经使用 DiffieHellman 成功交换了密钥,现在想要使用这些密钥来加密我需要使用 RSA 加密通过线路发送的对象。
DiffieHellman 为我提供了实际密钥:
问题 #1
有没有办法将实际密钥直接导入到 RSACryptoServiceProvider 变量中?
看来我只能找到基于 XML 导入的示例,但这些示例具有我无法从 DiffieHellman 获得的额外信息(例如对于公钥,XML 带有指数值,对于私钥,XMLS 带有 P、Q、DP、DQ) ,逆......DiffieHellman 都没有提供)
问题#2
将提供的 DiffieHellman 私钥/公钥组合到基于 RSA 的加密调用中的正确方法是什么,以便调用加密/解密可以在两端的线路上进行?
c# encryption cryptography encryption-asymmetric public-key-encryption
编辑:这个问题没有意义。我将 .vshost.config 与 exe.config 混合在一起。这该怎么办?
程序.cs主要:
databaseName = System.Configuration.ConfigurationManager.AppSettings["DatabaseName"];
databaseUser = System.Configuration.ConfigurationManager.AppSettings["DatabaseUser"];
databasePwd = System.Configuration.ConfigurationManager.AppSettings["DatabasePassword"];
port = System.Configuration.ConfigurationManager.AppSettings["Port"];
logDirectory = System.Configuration.ConfigurationManager.AppSettings["LogDirectory"];
strLogLevel = System.Configuration.ConfigurationManager.AppSettings["LogLevel"];
EncryptConfigSection("appSettings");
Run Code Online (Sandbox Code Playgroud)
这就是我加密文件的方式:
private static void EncryptConfigSection(string sectionKey)
{
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
ConfigurationSection section = config.GetSection(sectionKey);
if (section != null)
{
if (!section.SectionInformation.IsProtected)
{
if (!section.ElementInformation.IsLocked)
{
section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
section.SectionInformation.ForceSave = true;
config.Save(ConfigurationSaveMode.Full);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
该文件被复制和加密,就像我在网上找到的示例一样:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings configProtectionProvider="DataProtectionConfigurationProvider">
<EncryptedData>
<CipherData>
<CipherValue>AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAAvsQ9Wtc58EC5EZCEq91EogQAAAACAAAAAAADZgAAwAAAABAAAClVHhpR5xAw4KFNyrANtavAAAAAASAAACgAAAAEAAAABHkhg2ztiY3bdWhTG9iy6twAAAAF5mAHt7oDQWCgc1iLL2hYUJZgmquU8XsojjqXVQdV1CaW3XEBXBDhN30DEZizP3F5rGGMCjL9CVjHfsPAfvVYyRHCcup22BoByb5y/MDujaASpaWZYcdxSxLijT/Zq3zB8hiWyWPruY0G7emYEOq/xQAAADkgStCMABwo3oZx/VXHD41wrsjXg==</CipherValue>
</CipherData>
</EncryptedData>
</appSettings>
</configuration>
Run Code Online (Sandbox Code Playgroud)
但下次启动时,我就无法读取它了。所有读取的值均为空。我很自然地从文件夹中删除了原始的、未加密的文件。
我在jsp中做了一个登录页面。
用户名和密码存储在mysql中。
我想要一些加密密码的建议,然后解密密码(以验证密码标签中的内容是否与该用户名数据库中的内容相同)。
下面的代码给了我这样的字符串“但我想要的是以更短的形式
3TA3cATum2VMStTsnJ6DPz5Xx5JH2SoZDdevsd2WJrYapJQjcTOOQ=="加密(需要转换类似小URL的东西)mystring(strr)
private byte[] key={};
private byte[] IV={18,52,86,120,144,171,205,239};
public string prvtkey="!#$a54?3";
string strr="placeesOFPrj/modulesNamee/mypagesss/ds2.aspx";
key = System.Text.Encoding.UTF8.GetBytes(prvtkey);
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
byte[] inputByteArray = Encoding.UTF8.GetBytes(strr);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(key, IV), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
txt.Text=Convert.ToBase64String(ms.ToArray());
Run Code Online (Sandbox Code Playgroud) 我正在使用 CrypstoJS (来自https://code.google.com/p/crypto-js)进行加密和解密。
我加密了一个字符串,如下所示:
var hash = CryptoJS.HmacSHA512("Message", "Secret Passphrase");
Run Code Online (Sandbox Code Playgroud)
那怎么解密???我想使用 SHA512 进行加密/解密。
请帮我..
我有一段简单的 JavaScript:
<html>
<script type="text/javascript" src="http://cdn.rawgit.com/travist/jsencrypt/v2.1.0/bin/jsencrypt.js"></script>
<script type="text/javascript">
var message = "This is my message"
// we create a new JSEncrypt object for rsa encryption
var rsaEncrypt = new JSEncrypt();
var publicKey = "-----BEGIN PUBLIC KEY-----" +
"\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQK" +
"BgQCQDxDFOYJpkCaqeX4CBVNCtBjX\nMZgGMo" +
"lSs2wYrVu1ixr36KpeJcRcYhz+AnyhnUpYkgk" +
"+hEqJtDSNirU5Dk5oVYYi\ngf2uLogV5Tp/ka" +
"K49r9vtxldcHraZIgNQjcdeQUd/viKd/3DvM8" +
"naWR/mTG0nCBE\nrEQkATW/xXynJh/COQIDAQ" +
"AB\n-----END PUBLIC KEY-----"
rsaEncrypt.setPublicKey(publicKey);
var encryptedMessage = rsaEncrypt.encrypt(message);
console.log(encryptedMessage)
</script>
</html>
Run Code Online (Sandbox Code Playgroud)
我觉得每次运行时都应该在控制台中产生相同的输出,但事实并非如此。
示例输出:
abqE+YkCMKFWgsazbZpfGvoXLci9FL/wZLYUMR6ZFkolsvJC5MdJgq5yn+AXXy8xlKHDOry6czAaOQOTl2HXdKSfsypc8nqDU8Sx5PuEgMYjvJ/dEyfU6jVuxfH1Qmuk6aOGVHePNfDlC4kSjgp1RXToSP5NqAEi24EuMx3uulI=
OzZM03Pki3o631KOuZ5nyQKu1xXRbLHhrR0WnjE5Ns5SssoiCEwlrS+svtP0cbZaYWZJc+FlZQNFUam4iC233BKnY5Nrr5Ppj14eaBvJ4x3FR8FiLwtyEW7nTzisAS7Ys2RKPjUzmkiOCZHwIpXnUO10KVo8763+JIuDB0cDPS4=
Run Code Online (Sandbox Code Playgroud)
谁能解释这种行为?
我正在尝试使用 加密密码mcrypt_encrypt()。它在 上工作正常localhost,但是当进入在线状态时,我的输出是""并且我收到此警告:
警告:mcrypt_encrypt():此算法不支持大小为 10 的密钥。仅支持尺寸为 16、24 或 32 的密钥
这是我正在使用的代码:
$text="thisismypassword123";
$salt="1234567824";
return trim (
base64_encode (
mcrypt_encrypt (
MCRYPT_RIJNDAEL_256, $salt, $text, MCRYPT_MODE_ECB, mcrypt_create_iv (
mcrypt_get_iv_size (
MCRYPT_RIJNDAEL_256, MCRYPT_MODE_ECB
),
MCRYPT_RAND
)
)
)
);
Run Code Online (Sandbox Code Playgroud)
造成这种情况的原因是什么?我可以采取什么措施来解决这个问题?
php encryption mcrypt encryption-symmetric password-encryption
更新:问题是我!我犯了一个错误,否则两个 Cods(下面和PS上的那个都是正确的)但仍然感谢 @Luke Park 的精彩回答,我学到了一些新东西。
我对加密/解密算法不熟悉,因此我在网上搜索并找到了这个类:
代码是:(我在Decrypt方法中添加了一个 Try/Catch,以防密码错误return "";)
using System;
using System.Text;
using System.Security.Cryptography;
using System.IO;
using System.Linq;
namespace EncryptStringSample
{
public static class StringCipher
{
// This constant is used to determine the keysize of the encryption algorithm in bits.
// We divide this by 8 within the code below to get the equivalent number of bytes.
private const int Keysize = 256;
// This constant …Run Code Online (Sandbox Code Playgroud) 我尝试进行 AES 加密,并且正在生成盐。但是我遇到了一些问题。下面的代码工作正常,但每当我加密第二个等文件时,文件中的盐就会被覆盖。关于如何将 salt 字节 [] 附加到 salt fil 中而不覆盖它有什么建议吗?
\n\n伙计们..我更新了我的代码..感谢那部分,虽然它解决了覆盖问题,但它没有进入下一行。
\n\n我的文件上的输出: \xcb\x9cV"\xc3\x83\xc2\xb7\xc3\x92\xc2\xb2\xc3\x964\xc3\xb4\xc2\xa6\xc5\x92T\xe2\x80\xb0m\xc3 \x8a\xc3\xae0\xe2\x80\x98Z^\'\xc3\xbb\xe2\x80\xa2\xc5\xa1\xc3\x99K\xc2\xb7 = 这是两个盐的组合。
\n\n知道如何将其附加到下一行吗?
\n\n我尝试 saltoutfile.write("/n") 但不起作用
\n\n public byte[] generateSalt() throws IOException{\n //generate Salt value\n // password, iv and salt should be transferred to the other end\n // in a secure manner\n // salt is used for encoding\n // writing it to a file\n // salt should be transferred to the recipient securely\n // for decryption\n byte[] salt = new byte[8];\n SecureRandom …Run Code Online (Sandbox Code Playgroud) encryption ×10
c# ×4
javascript ×3
java ×2
php ×2
.net ×1
app-config ×1
append ×1
arrays ×1
asp.net ×1
base64 ×1
cryptography ×1
file ×1
jsp ×1
mcrypt ×1
mysql ×1
node.js ×1
public-key ×1
short-url ×1
string ×1
winforms ×1