标签: encryption

使用AES-128加密和解密字符串

我在加密128位密钥时得到了它.我该怎么做才能扭转这个过程.我几乎要坐在这里差不多一个小时才想到这个,但我不能.我刚接触这个btw.

样本输入是:J§???????ÿK??{??

输出应该是: hello

在这个计划中:

样本输入是:hello

输出是: J§???????ÿK??{??...

public class en {
    public static void main(String[] args){
      ...
    try{
      System.out.print("Enter text: ");
        String text = dataIn.readLine();
        String key = "dAtAbAsE98765432"; // 128 bit key

     // Create key and cipher
     Key aesKey = new SecretKeySpec(key.getBytes(), "AES");
     Cipher cipher = Cipher.getInstance("AES");

     // encrypt the text
     cipher.init(Cipher.ENCRYPT_MODE, aesKey);
     byte[] encrypted = cipher.doFinal(text.getBytes());
     System.err.println("Encrypted: " + new String(encrypted));

     // Decrypt the text
     cipher.init(Cipher.DECRYPT_MODE, aesKey);
     String decrypted = new String(cipher.doFinal(encrypted));
     System.err.println("Decrypted: " + …
Run Code Online (Sandbox Code Playgroud)

java encryption aes

3
推荐指数
2
解决办法
4万
查看次数

RSA加密(模数/指数)给出"消息大于模数"

我试图使用RSA加密消息,这是我的代码:

byte[] message = new byte[] { (byte) 0xbe, (byte) 0xef, (byte) 0xef };
Cipher cipher = Cipher.getInstance("RSA");

KeyFactory keyFactory = KeyFactory.getInstance("RSA");

String mod = "B390F7412F2554387597814A25BC11BFFD95DB2D1456F1B66CDF52BCC1D20C7FF24F3CCE7B2D66E143213F64247454782A377C79C74477A28AF6C317BE68BC6E8FF001D375F9363B5A7161C2DFBC2ED0850697A54421552C6288996AC61AF5A9F7DE218ABBC75A145F891266615EB81D11A22B7260F7608083B373BA4BC0756B";
String exp = "010001";

RSAPublicKeySpec pubKeySpec = new RSAPublicKeySpec(new BigInteger(Hex.fromString(mod)), new BigInteger(Hex.fromString(exp)));
RSAPublicKey pubKey = (RSAPublicKey) keyFactory.generatePublic(pubKeySpec);

cipher.init(Cipher.ENCRYPT_MODE, pubKey);

byte[] cipherText = cipher.doFinal(message);
System.out.println("cipher: " + new String(cipherText));
Run Code Online (Sandbox Code Playgroud)

我总是得到错误:

javax.crypto.BadPaddingException: Message is larger than modulus
    at sun.security.rsa.RSACore.parseMsg(Unknown Source)
    at sun.security.rsa.RSACore.crypt(Unknown Source)
    at sun.security.rsa.RSACore.rsa(Unknown Source)
    at com.sun.crypto.provider.RSACipher.doFinal(RSACipher.java:352)
    at com.sun.crypto.provider.RSACipher.engineDoFinal(RSACipher.java:382)
    at javax.crypto.Cipher.doFinal(Cipher.java:2087)
Run Code Online (Sandbox Code Playgroud)

我也尝试过BouncyCastle,但我仍然遇到同样的错误.

注意 …

java encryption cryptography rsa bouncycastle

3
推荐指数
1
解决办法
4863
查看次数

为什么File.copy可以工作但是File.OpenRead提示访问被拒绝?

我想复制另一个进程正在使用的加密文件。

这有效:

System.IO.File.Copy("path1", "path2",true);
Run Code Online (Sandbox Code Playgroud)

但以下代码无法正常工作。提示“文件访问被拒绝”错误:

using (FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read))//access denied open file
{
    using (Stream copyFileStream = new StreamDecryption(new FileStream(copyTo, FileMode.Create)))
    {

    }
}
Run Code Online (Sandbox Code Playgroud)

如果文件被另一个进程使用,我该如何复制加密文件?

谢谢

更新:我使用此代码并为我工作:

using (var fileStream = new System.IO.FileStream(@"filepath", System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite))
{

}
Run Code Online (Sandbox Code Playgroud)

c# encryption copy

3
推荐指数
1
解决办法
3858
查看次数

WCF安全性:TransportWithMessageCredential和消息安全模式之间的区别

我想知道TransportWithMessageCredential Vs Message在WCF安全性方面的区别.

我所知道的是:

传输安全性: 用于在两个端点之间提供点对点安全性.

消息安全性:它提供端到端的安全性.因为消息安全性直接加密和签署消息,所以拥有中介不会破坏安全性.

如果我们使用TransportWithMessageCredential 模式,SOAP消息(Header和Body)是否加密?

我担心的是我希望在WCF服务器和我的WinForms客户端之间加密应用程序数据.

security encryption wcf wcf-security

3
推荐指数
1
解决办法
7513
查看次数

C#Rijndael解密返回额外的问号字符

我正在组织一些非常基本的对称加密/解密代码以供将来使用.我能够成功加密和解密...只有一个小问题.

这是我的代码,它从流中读入并解密到另一个流:

public void Encrypt(Stream input, Stream output) {
    byte[] key = Encoding.UTF8.GetBytes(_pw);
    byte[] iv = Encoding.UTF8.GetBytes(GenerateInitVector());
    RijndaelManaged rm = new RijndaelManaged();
    CryptoStream cs = new CryptoStream(
        output,
        rm.CreateEncryptor(key, iv),
        CryptoStreamMode.Write);
    int data;
    while ((data = input.ReadByte()) != -1)
        cs.WriteByte((byte) data);
    cs.Close();
}

public void Decrypt(Stream input, Stream output) {
    byte[] key = Encoding.UTF8.GetBytes(_pw);
    byte[] iv = Encoding.UTF8.GetBytes(GenerateInitVector());
    RijndaelManaged rm = new RijndaelManaged();
    CryptoStream cs = new CryptoStream(
        input,
        rm.CreateDecryptor(key, iv),
        CryptoStreamMode.Read);
    int data;
    while ((data = cs.ReadByte()) != -1) …
Run Code Online (Sandbox Code Playgroud)

c# encryption cryptography rijndaelmanaged

3
推荐指数
1
解决办法
1273
查看次数

Codeigniter密码解密

目前我正在试图从具有使用加密的口令以前的数据库导入用户列表笨的Mcrypt协议.

坦率地说,我不知道我在做什么:(我已经在我的服务器上安装了框架,并试图从框架中调用解密类,并且它根本就没有.

我的目标是解密密码和将它们加密到Joomla(我认为至少使用过的)md5加密和盐渍密码.这是我需要解密的密码示例:

r5WEX++ZKggg7d6fQYAZfFOm/z3nTJmxQA00zVWhhn7cvmrSrIm/NYI51o9372qf6JtYQEil72b4JzszVo+oPg==
Run Code Online (Sandbox Code Playgroud)

我想我可以处理重新加密,我只是不知道如何解密这些东西.谢谢任何可以提供帮助的人!

php encryption codeigniter joomla3.0

3
推荐指数
1
解决办法
2万
查看次数

Python Crypto,RSA公钥/私钥,包含大文件

我现在知道RSA公钥/私钥只能一次加密非常短的输入,但任何人都可以提供一种方法来加密任何类型的文件(.txt,.phf,.exe等)只有公钥/私钥?我不想要额外的AES密钥.

这是我的代码,在使用公钥和私钥对进行加密和解密后,我没有收到原始内容.我不关心加密或解密的安全性,我只想让简单的加密解密工作在它可能需要的任何输入上,无论它有多长或多大.

from Crypto.PublicKey import RSA
from Crypto import Random


random_generator = Random.new().read
key = RSA.generate(1024, random_generator)
public_key = key.publickey()

f = open('C:\Users\Administrator\Desktop\jack.txt','r').read()

print 'original content: '+ f

enc_data = public_key.encrypt(f, 32)
print 'encrypted data: '
print enc_data

dec_data = key.decrypt(enc_data)
print 'decrypted data: '+ dec_data
Run Code Online (Sandbox Code Playgroud)

这是输出:

original content: Python Cryptography Toolkit

A collection of cryptographic modules implementing various algorithms and protocols.

Subpackages:

Crypto.Cipher
Secret-key (AES, DES, ARC4) and public-key encryption (RSA PKCS#1) algorithms
Crypto.Hash
Hashing algorithms (MD5, SHA, HMAC) …
Run Code Online (Sandbox Code Playgroud)

python encryption cryptography rsa pycrypto

3
推荐指数
2
解决办法
2万
查看次数

如何在WildFly中启用某些密码套件?

我想在我的WildFly应用服务器上显式启用某些密码套件.因此,我尝试在wildflys standalone.xml中编辑配置.

假设我想启用AES128-GCM-SHA256密码(来自OpenSSL文档的密码套件名称).

我已经编辑了我的WildFly服务器的standalone.xml文件,如下所示:

<https-listener name="listener" socket-binding="https" security-realm="ssl-realm" enabled-cipher-suites="AES128-GCM-SHA256"/>
Run Code Online (Sandbox Code Playgroud)

WildFly正常启动,但是当我在浏览器中打开页面时,会显示一条错误消息.Chrome说:

ERR_SSL_PROTOCOL_ERROR

Firefox说:

ssl_error_internal_error_alert

我用WildFly 8.1和8.2试过这个.

那里有谁可以给​​我建议如何正确启用某些密码套件?

关心汤姆

encryption ssl wildfly wildfly-8

3
推荐指数
1
解决办法
7627
查看次数

加密.NET二进制序列化流

我正在用C#学习加密,我遇到了麻烦.我有一些Rijndael加密代码,它与字符串完美配合.但是现在我正在研究序列化并且BinaryWriter没有任何保护地写入类的数据.我正在使用此代码进行测试 ; 有没有办法"加密类",或类似的东西?

为了澄清这个问题,这是我的代码:

FileStream file = new FileStream(Environment.CurrentDirectory + @"\class.dat", FileMode.Create);
using (BinaryWriter sw = new BinaryWriter(file))
{
    byte[] byt = ConverteObjectEmByte(myVarClass);
    sw.Write(byt);
}
Run Code Online (Sandbox Code Playgroud)

这就是我读它的方式:

MyClass newMyVarClass;
FileStream file = new FileStream(Environment.CurrentDirectory + @"\class.dat", FileMode.Open);
using (BinaryReader sr = new BinaryReader(file))
{
    // 218 is the size of the byte array that I've tested (byt)
    myNewVarClass = (MyClass)ConverteByteEmObject(sr.ReadBytes(218));
}
Run Code Online (Sandbox Code Playgroud)

谢谢!

c# encryption

3
推荐指数
1
解决办法
4071
查看次数

在Postgres中搜索加密字段

我正在尝试使用“ pgp_sym_encrypt”查询postgres中的加密字段。我通过将表中的所有名字设置为加密值来运行测试:

update person set first_name = pgp_sym_encrypt('test', 'password');
Run Code Online (Sandbox Code Playgroud)

然后选择:

select * from person where first_name = pgp_sym_encrypt('test', 'password');
Run Code Online (Sandbox Code Playgroud)

这将不返回任何结果。

如果我将其更改为使用常规的postgres加密,它将返回表中的所有行:

update person set first_name = encrypt('test', 'password', 'aes');
select * from person where first_name = encrypt('test', 'password', 'aes');
Run Code Online (Sandbox Code Playgroud)

我当前的postgres版本是:postgres(PostgreSQL)9.4.0。在这种情况下,first_name字段是一个bytea字段。

有谁知道为什么不能使用“ pgp_sym_encrypt”来工作?

谢谢!

sql security encryption postgresql

3
推荐指数
1
解决办法
2077
查看次数