我知道私钥和公钥在数学上是相关的,用一个密钥加密的数据只能与其他密钥相关联.我的问题是私钥总是用于加密数据,而公钥总是用来解密它?或者可以是副版本,如果是这样,你可以给出一些示例应用程序,其中它用于其他方向(公钥加密和私钥解密)?
如何在.NET中加密某些内容并在PHP中解密?
我正在使用下面的方法,如果我输入了正确的键,一切都会正常。但是,如果我输入了错误的密钥,我将收到BadPaddingException:pad块损坏……我做错了吗?
public void initKey(String passwd, byte[] salt) throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchProviderException{
byte[] localsalt = salt;
PBEKeySpec password = new PBEKeySpec(passwd.toCharArray(),localsalt, 1024,128);//, localsalt, 1000, 128); //128bit enc aes
SecretKeyFactory factory = SecretKeyFactory.getInstance("PBEWithMD5And128BitAES-CBC-OpenSSL","BC");
PBEKey key = (PBEKey) factory.generateSecret(password);
encKey = new SecretKeySpec(key.getEncoded(), "AES");
}
public String txt2enc(String etxt) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException, UnsupportedEncodingException {
final Cipher cipher = Cipher.getInstance("AES");//AES
cipher.init(Cipher.ENCRYPT_MODE, encKey);
byte[] encrypted = cipher.doFinal((etxt).getBytes("UTF-8"));
return Base64.encodeToString(encrypted, 0);
}
//decryption
public String txt2dec(String dtxt) throws InvalidKeyException, NoSuchAlgorithmException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException, …Run Code Online (Sandbox Code Playgroud) 我正在开发一个客户端-服务器应用程序,该应用程序要求一些文件在发送给客户端之前必须先使用私钥进行签名。然后,客户端将使用公钥验证签名。因此,私钥将始终需要位于服务器上,并且可由服务器应用程序读取。
问题是我想知道在哪里存储我的私钥,以防万一服务器受到破坏时更安全。
我应该将其存储在数据库中还是应该将其存储为文件并使用文件许可权进行控制?
谢谢。
我试图用Delphi Encryption Compendium中的Cipher1 3.0,第一部分解密用Delphi加密的c#中的一个字符串.我使用TCipher_Rijndael.
我加密的字符串是:this-is-a-test-example
密码:通过
加密值为:iKBC8kX4ZEk4A1pCj6jwEegqjpxhqw ==
当我尝试在c#中解密时,我发现错误:要解密的数据长度无效.
有没有人有同样的问题,什么是解决方案?
这是c#中的解密方法:
public static byte[] Decrypt(byte[] cipherData,
byte[] Key, byte[] IV)
{
MemoryStream ms = new MemoryStream();
Rijndael alg = Rijndael.Create();
alg.Key = Key;
alg.IV = IV;
CryptoStream cs = new CryptoStream(ms,
alg.CreateDecryptor(), CryptoStreamMode.Write);
cs.Write(cipherData, 0, cipherData.Length);
cs.Close();
byte[] decryptedData = ms.ToArray();
return decryptedData;
}
Run Code Online (Sandbox Code Playgroud)
这里是Delphi中的加密代码:
with TCipher_Rijndael.Create('pass', nil) do
begin
memo2.lines.add ( CodeString( 'this-is-a-test-example' , paEncode, fmtDEFAULT));
Free;
end;
Run Code Online (Sandbox Code Playgroud)
谢谢.
我正在为需要进行加密和解密的Drupal模块提供一些代码.我不认为我可以假设Mcrypt模块安装在Drupal系统上.我可以使用什么作为替代加密机制?
这不是财务方面的东西,所以我不需要复杂的密码学,但更好的是...
我收到的'要解密的数据长度无效.' 尝试解密字符串时出错.我在这个网站上看了很多其他对这个错误的引用,并尝试了一些在那里找到的建议,但到目前为止没有任何工作.
我确信我缺少一些基本的东西,但我看不出它是什么.
我在加密和解密时使用相同的密钥和IV.我FlushFinalBlock()在加密和解密时添加了调用.我甚至试图设置encryptStream.Position = 0,但是抛出一个ObjectDisposedException.
我创建了一个控制台应用程序来说明问题.代码完整如下:
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
namespace Crypto
{
class Program
{
static void Main(string[] args)
{
_CryptoString = AESStringEncryption(CRYPTO_STRING);
_CryptoString = AESStringDecryption(_CryptoString);
}
private const string CRYPTO_STRING = "The quick brown fox jumped over the lazy dog.";
private static byte[] _KY = { 47, 53, 94, 65, 243, 197, 42, 80, 125, 255, 144, 41, 130, 76, 2, 142, 43, 1, 120, 124, 255, …Run Code Online (Sandbox Code Playgroud) 所以我正在编写一个加密和解密文本文件的程序,但是当我使用除"Blowfish"之外的加密(例如"Blowfish/CBC/PKCS5Padding")时,我似乎总是得到这个错误.我得到的是:
Exception in thread "main" java.security.NoSuchAlgorithmException: Blowfish/CBC/PKCS5Padding KeyGenerator not available
at javax.crypto.KeyGenerator.<init>(DashoA13*..)
at javax.crypto.KeyGenerator.getInstance(DashoA13*..)
at Encryptor.<init>(Encryptor.java:87)
at Encryptor.main(Encryptor.java:30)
Run Code Online (Sandbox Code Playgroud)
我的一部分代码:
import java.security.MessageDigest;
import java.security.SecureRandom;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
public class Encryptor2 {
private IvParameterSpec ivSpec;
private SecretKeySpec keySpec;
private Cipher cipher;
public static void main(String[] args) throws Exception {
Encryptor2 e = new Encryptor2(
"averylongtext!@$@#$#@$#*&(*&}{23432432432dsfsdf");
String enc = e.encrypt("john doe");
String dec = e.decrypt(enc);
}
public Encryptor2(String pass) throws Exception {
// setup AES cipher in CBC mode with …Run Code Online (Sandbox Code Playgroud) 我想知道你是否可以一遍又一遍地使用md5,或者一遍又一遍地使用sha1,例如:
$pass = md5($pass);
$pass = sha1($pass);
$pass = md5($pass);
$pass = md5($pass);
Run Code Online (Sandbox Code Playgroud)
而且还有它的工作?因此,它一次又一次地加密加密的字符串,因为我想制作一个严重加密的密码系统,以便没有人可以破解,我担心我正在创建的额外算法是否有效.
怎么正确打电话DBMS_OBFUSCATION_TOOLKIT.DESEncrypt?(如果可能,不使用PL/SQL)
select DBMS_OBFUSCATION_TOOLKIT.DESEncrypt('x','y') from dual;
Run Code Online (Sandbox Code Playgroud)
因为DESEncrypt超载而无效:
ORA-06553: PLS-307: Too many declarations of "DESENCRYPT" match this call
06553. 00000 - "PLS-%s: %s"
*Cause:
*Action:
Run Code Online (Sandbox Code Playgroud)
有没有办法选择DESENCRYPT的一个实现(可能是VARCHAR2变体)来避免这个错误?