Tag: 加密

什么metod KeyAgreement.generateSecret(String algorithm)呢?

我们实现了Diffie-Hellman密钥交换算法: KeyAgreement aKeyAgree = KeyAgreement.getInstance(“DH”); keyAgreement.init(myPrivateKey); keyAgreement.doPhase(otherPublicKey) 现在我们需要生成一个用于AES加密的秘密。 有方法generateSecret(String algorithm) 。 我想我应该用’AES’说法来称呼它。 但对于DH,我使用512位长度的公钥,所以秘密也应该是512位长度。 但AES允许256位长度的密钥作为最大值。 没有参数的plain方法generateSecret()返回512位DH密钥。 但是generateSecret(String)呢? 它如何将512位密钥转换为256/128位AES密钥?

使用在openjre中需要Java Policy Files的加密

如果我想使用java和加密密钥长度超过128位,我必须使用Java策略文件。 如何使用openjre启动并运行这些应用程序? 我得到了相同的错误,我使用oracle jre没有策略文件,但我不能简单地使用Oracle策略文件? 或者我可以吗? 或者用openjdk帮助构建项目? 谢谢

阅读和插入Chrome Cookie Java

这实际上正是我在寻找但在Java中: Chrome中的加密Cookie 我在这里找到了针对Java提到的“Windows Data Protection API(DPAPI)”: http://jdpapi.sourceforge.net/ 但它的“过时”或仅适用于32位平台。 SQLite连接和结果当然是有效的,这就是我得到的: public void getDecryptedValue() { try { Statement stmt = connection.createStatement(); String sql = “SELECT * FROM cookies”; ResultSet rs = stmt.executeQuery(sql); int cookieCount = 1; while (rs.next()) { log.debug(“####### Cookie ” + cookieCount + ” ############”); String host_key = rs.getString(“host_key”); log.debug(host_key); byte[] encrypted_value = rs.getBytes(“encrypted_value”); //this […]

PBE:在尝试解密之前validation密码

我正在用Java创建一个应用程序,我希望允许用户使用他们选择的密码加密文件(或文件夹 – 我会压缩目录)。 我目前有以下方法: static Cipher createCipher(int mode, String password) throws Exception { PBEKeySpec keySpec = new PBEKeySpec(password.toCharArray()); SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(“PBEWithMD5AndDES”); SecretKey key = keyFactory.generateSecret(keySpec); MessageDigest md = MessageDigest.getInstance(“MD5”); md.update(“input”.getBytes()); byte[] digest = md.digest(); byte[] salt = new byte[8]; for (int i = 0; i 0){ out.write(buffer, 0, numRead); System.out.println(toHexString(buffer, 0, numRead)); } } […]

使用流解密和解压缩以限制内存使用?

我有一个非常大的zip文件,2.5gb,是加密的。 我无法将整个文件解密到内存中并解压缩到那里进行生产。 所以我试图使用流来限制使用的内存量。 我已经连接了以下内容(为了清晰起见,error handling和流关闭): SecretKeySpec keySpec = new SecretKeySpec(myKey “AES”); Cipher cipher = Cipher.getInstance(“AES/CBC/PKCS5Padding”); FileInputStream fis = new FileInputStream(new File(pathToEncryptedFile)); CipherInputStream cis = new CipherInputStream(fis, cipher); ZipInputStream zis = new ZipInputStream(new BufferedInputStream(cis)); ZipEntry ze = null; while ((ze = zis.getNextEntry()) != null) { String filename = ze.getName(); System.out.println(“Found zip entry: ” + filename); } […]

阅读Java中的私有加密密钥

我有以下代码: PEMParser pemParser; File telexuskeys = new File(locationKey); if(telexuskeys.exists()) pemParser = new PEMParser(new FileReader(telexuskeys)); else{ usage(ops); throw new FileNotFoundException(“The key file (company’s certificate) doesn’t exist!”); } System.out.println(“Loading company’s certificate”); Object object = pemParser.readObject(); Object object2 = pemParser.readObject(); PEMDecryptorProvider decProv = new JcePEMDecryptorProviderBuilder().build(passwordPem.toCharArray()); JcaPEMKeyConverter converter = new JcaPEMKeyConverter().setProvider(“BC”); byte[] keyBytes = PrivateKeyInfo.getInstance(object2).getEncoded(); PKCS8EncodedKeySpec spec = new […]

Java JCE无限强度加密安全策略文件

在JRE更新后,JCE策略文件(在{java.home} / lib / security中)是否被标准强度策略文件覆盖? 或者这些是否在JRE更新中独自存在? 编辑:有谁知道Mac OS X JRE是否附带无限制的策略文件? 谢谢 乔恩

在Amazon S3中使用KMS密钥解密文件时出错

我正在尝试将Amazon S3用作带加密的文件系统。 我已成功使用KMS加密密钥(服务器端加密)在AWS S3服务器上实现上载文件。 请找到以下工作代码: 对于加密: private static final String AWS_KMS_KEY = “—KMS Key—” private static final String BUCKET_NAME = “—bucket name—” private static final String keyName = “—display key name—” private static final String filePath = “—File Path—” private static final String ACCESS_KEY_ID = “—aws accesskey—” private static final String SECRET_ACCESS_KEY = “—aws secret […]

Java:摆脱`Cipher.init()`开销

我需要提高以下方法的性能: private byte[] decrypt(final byte[] encrypted, final Key key) throws … { this.cipher.init(Cipher.DECRYPT_MODE, key); return this.cipher.doFinal(encrypted); } cipher对象(“AES / ECB / NoPadding”)在构造函数中初始化,因此可以重用它。 使用ECB,因为encrypted数组将始终只包含16个字节的数据(即1个数据块)。 使用128位密钥。 这种方法被称为数百万次,以解密16字节的块,每次使用不同的密钥。 例如,这个方法被调用如下: final List keys = List with millions of keys final byte[] data = new byte[] { … 16 bytes of data go here …} for (final Key key : […]

解密错误:Pad块损坏

我有以下代码。 byte[] input = etInput.getText().toString().getBytes(); byte[] keyBytes = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17 }; SecretKeySpec key = new SecretKeySpec(keyBytes, “AES”); Cipher cipher = Cipher.getInstance(“AES/ECB/PKCS7Padding”, “BC”); // encryption pass cipher.init(Cipher.ENCRYPT_MODE, key); byte[] cipherText = […]