Tag: secret key

Java AES:没有安装的提供程序支持此密钥:javax.crypto.spec.SecretKeySpec

我正在尝试设置128位AES加密,并且我在Cipher.init上抛出一个exception: No installed provider supports this key: javax.crypto.spec.SecretKeySpec 我正在使用以下代码在客户端生成密钥: private KeyGenerator kgen; try { kgen = KeyGenerator.getInstance(“AES”); } catch (NoSuchAlgorithmException e) { // TODO Auto-generated catch block e.printStackTrace(); } kgen.init(128); } SecretKey skey = kgen.generateKey(); 然后,此密钥将作为标头传递给服务器。 使用此函数进行Base64编码: public String secretKeyToString(SecretKey s) { Base64 b64 = new Base64(); byte[] bytes = b64.encodeBase64(s.getEncoded()); return new String(bytes); } […]

如何在Java中生成一次密钥并在2个不同的程序中使用该密钥

我的目标是编写一个Java程序来使用AES algorithm加密文本文件( cipher text )。 然后,编写另一个程序来解密该加密文件( cipher text )以获取纯文本。 我想使用相同的密钥(相同的密钥,生成一次,保存在某处,并在加密和解密程序中使用它)进行加密和解密过程。 如果我生成密钥并在同一程序中逐行进行加密和解密,那么它可以完美地工作。 以下是该工作代码段: String strDataToEncrypt = new String(); String strCipherText = new String(); String strDecryptedText = new String(); KeyGenerator keyGen = KeyGenerator.getInstance(“AES”); keyGen.init(128); SecretKey secretKey = keyGen.generateKey(); Cipher aesCipher = Cipher.getInstance(“AES”); aesCipher.init(Cipher.ENCRYPT_MODE,secretKey); strDataToEncrypt = “any text input”; byte[] byteDataToEncrypt = strDataToEncrypt.getBytes(); byte[] byteCipherText = aesCipher.doFinal(byteDataToEncrypt); strCipherText […]

JWT中的“秘密”应该是什么?

我将把JWT应用到我使用Java-Jersey开发的REST API中。 我正在为JWT使用这个库 – https://github.com/auth0/java-jwt 关于JWT – Secret,我几乎没有问题 这个Secret必须是独一无二的吗? 我应该使用用户密码的哈希版本来保密吗? (然后它不是唯一的)这是因为当用户更改他的密码时,他的令牌将自动无效。

PBKDF2WithHmacSHA512 Vs. PBKDF2WithHmacSHA1

我正在研究一个Java认证子系统,该子系统规定在DB中存储密码为PBKDF2生成的哈希,我现在正在尝试决定是否应该使用SHA1或SHA512作为PFR。 我仔细检查了两者的规格,但我们在数学上非常密集地跟随它。 有更好的加密理解的人可以解释PBKDF2WithHmacSHA512与PBKDF2WithHmacSHA512区别吗? 这是我正在尝试做的事情: private static final int HASH_BYTE_SIZE = 64; // 512 bits private static final int PBKDF2_ITERATIONS = 1000; // generate random salt SecureRandom random = new SecureRandom(); byte salt[] = new byte[SALT_BYTE_SIZE]; // use salt size at least as long as hash random.nextBytes(salt); // generate Hash PBEKeySpec spec = new PBEKeySpec(password, salt, […]