Tag: 加密对称

用盐打开Openssl AES 256 CBC Java Decrypt文件

我已经尝试了几天用java解密用openssl加密的消息。 使用以下命令加密消息: openssl enc -e -aes-256-cbc -kfile $ file.key -in toto -out toto.enc。 文件file.key包含256位的对称密钥。 在命令中没有指定salt,但文件以Salted__开头。 这是我编写的类,试图解密文件,但即使通过删除文件的16个字符即:Salted__ + salt加密,也无法获得任何内容。 我得到错误:线程“main”中的exceptionjavax.crypto.BadPaddingException:给定最终块未正确填充。 有人能帮帮我吗? 非常感谢你。 public class Java { private static SecretKey key = null; private static Cipher cipher = null; public static void main(String[] args) throws Exception { String filename = RESOURCES_DIR + “toto.enc”; byte[] key = Base64.decode(“2AxIw+/AzDBj83OILV9GDpOs+izDFJEhD6pve/IPsN9=”); […]

这是一种安全的加密方法吗?

我正在编写一个Android应用程序,它使用对称密钥加密来保护敏感数据。 据我所知,Android只支持“PBEWithMD5AndDES”。 这个算法有多安全? 另外,我在下面包含了我的代码(非andriod)。 我的代码是否正确加密数据? import java.io.UnsupportedEncodingException; import java.security.InvalidAlgorithmParameterException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; import java.security.spec.InvalidKeySpecException; import java.security.spec.InvalidParameterSpecException; import javax.crypto.BadPaddingException; import javax.crypto.Cipher; import javax.crypto.IllegalBlockSizeException; import javax.crypto.NoSuchPaddingException; import javax.crypto.SecretKey; import javax.crypto.SecretKeyFactory; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.PBEKeySpec; import javax.crypto.spec.SecretKeySpec; public class CipherTest { private static class EncryptInfo { private final byte[] encryptedData; private final byte[] initVector; private […]

Android解密:最终确定密码时出错

我使用Android来加密和加密应用之间发送的图像。 加密效果很好但是当文件到达目的地时它不会解密。 现在我已经在目标应用程序中复制了该文件,并使用第三方软件成功解密了该文件。 我得到的错误是:在IllegalBlockSizeException引起的CipherInputStream(CipherInputStream.java:107)中“最终确定密码时出错”。 加密和解密代码如下: public static String encrypt(String plainFile, String encryptedFile) throws IOException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException { // Here you read the cleartext. File extStore = Environment.getExternalStorageDirectory(); FileInputStream fis = new FileInputStream(plainFile); // This stream write the encrypted text. This stream will be wrapped by // another stream. FileOutputStream fos = new FileOutputStream(encryptedFile); // […]

快速,简单易用的对称密码,用于Java中的整数加密

在Java中,具有这些属性的整数加密的密码函数是什么?: 快速 对称密钥算法 使用简单(即使用几行代码而不包含外部库) 可以指定输出长度(例如20个字符) 我只需要用它来加密/解密整数。

C#到Java DES加密

尝试创建java类,它将像下面的C#代码一样加密和解密。 下面是我的C#代码,我需要将其转换为Java。 有人可以帮我怎么做吗? 我已经这样做了将近2天但却找不到任何关于如何转换它的解决方案。 我是加密的新手。 注 – 似乎C#代码使用了ACME库。 但在我的java中,我不应该使用ACME jar文件。 public static string EncryptBase64(string key, string clearText) { if (key.Length > 8) key = key.Substring(0, 8); byte[] keyBytes = System.Text.Encoding.ASCII.GetBytes(key); byte[] clearBytes = GetClearTextBytes(clearText); // calculate the number of legitimate bytes in the last block byte lastByte = (byte)(8 – (clearBytes.Length – textEncoding.GetByteCount(clearText))); MemoryStream ms […]

使用JCE / JCA从主密钥中获取秘密

有人能指出我正确的方向吗? 我想使用JCE / JCA从主密钥中获取新密钥,我该如何实现? 问候。