Android加密不工作(PBKDF2WithHmacSHA256加密与AES / CBC / PKCS7Padding) [英] Android encryption not working (PBKDF2WithHmacSHA256 encryption with AES/CBC/PKCS7Padding)

查看:1071
本文介绍了Android加密不工作(PBKDF2WithHmacSHA256加密与AES / CBC / PKCS7Padding)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用密码算法AES / CBC / PKCS7Padding编写加密代码,HMAC算法HmacSHA256和密钥导出算法PBKDF2WithHmacSHA256在android的帮助下 JNCryptor 。但是它显示:



CryptorException:使用PBKDF2WithHmacSHA256无法从密码生成密钥





NoSuchAlgorithmException:SecretKeyFactory PBKDF2WithHmacSHA256实现未找到

  try {
SecretKeyFactory factory = SecretKeyFactory
.getInstance(KEY_DERIVATION_ALGORITHM);
SecretKey tmp = factory.generateSecret(new PBEKeySpec(password,
salt,getPBKDFIterations(),AES_256_KEY_SIZE * 8));
返回新的SecretKeySpec(tmp.getEncoded(),AES_NAME);
} catch(GeneralSecurityException e){
throw new CryptorException(String.format(
Failed to generate key from password using%s。,
KEY_DERIVATION_ALGORITHM),e);
}

任何帮助将不胜感激。


你可以看一下在项目的一个分支处, https://github.com/t0mm13b/AndroJNCryptor ,它试图对代码进行几个Android相关的改进。我相信你的问题可能在代码库中得到解决。



据我所知,没有可用的Android提供者提供一个名为 PBKDF2WithHmacSHA256 。非常沮丧!


I am trying to write an encryption code using Cipher Algorithm "AES/CBC/PKCS7Padding", HMAC algorithm "HmacSHA256" and key derivation algorithm "PBKDF2WithHmacSHA256" with the help of android JNCryptor. But it shows:

CryptorException: Failed to generate key from password using PBKDF2WithHmacSHA256

and

NoSuchAlgorithmException: SecretKeyFactory PBKDF2WithHmacSHA256 implementation not found

 try {
   SecretKeyFactory factory = SecretKeyFactory
     .getInstance(KEY_DERIVATION_ALGORITHM);
   SecretKey tmp = factory.generateSecret(new PBEKeySpec(password,
     salt, getPBKDFIterations(), AES_256_KEY_SIZE * 8));
   return new SecretKeySpec(tmp.getEncoded(), AES_NAME);
  } catch (GeneralSecurityException e) {
   throw new CryptorException(String.format(
     "Failed to generate key from password using %s.",
     KEY_DERIVATION_ALGORITHM), e);
  }

any help will be appreciated.

解决方案

Apologies for commenting and not realising you were talking about my software, JNCryptor.

You could take a look at a fork of the project, https://github.com/t0mm13b/AndroJNCryptor, which has attempted to make several Android-related improvements to the code. I believe your problem may be addressed in that code base.

As far as I know, there is no Android provider available that offers an algorithm named PBKDF2WithHmacSHA256. Quite frustrating!

这篇关于Android加密不工作(PBKDF2WithHmacSHA256加密与AES / CBC / PKCS7Padding)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆