jce

NoSuchAlgorithmException: Algorithm HmacSHA1 not available

早过忘川 提交于 2019-11-28 12:09:29
Look at the following line of java: Mac.getInstance("HmacSHA1"); If I put this in a simple test program, it runs without problems on my server. However, if I use this line in a container, I get java.security.NoSuchAlgorithmException: Algorithm HmacSHA1 not available at javax.crypto.Mac.getInstance(DashoA13*..) The same JDK installation is used in both cases. After googling around a bit, I managed to get it to work by doing two things: Copying sunjce_provider.jar from $JAVA_HOME/jre/lib/ext to the lib directory of the container. Adding the following line to my code: java.security.Security

How does one convert a public EC code point and curve name into a PublicKey?

末鹿安然 提交于 2019-11-28 10:30:32
I have two 32 byte long byte arrays representing the X and Y values for an EC Public Key. I know that the curve is the named curve "prime256v1". How can I turn that into a Java PublicKey object? The JCE appears to provide no facilities whatsoever to use named curves. Bouncycastle's example code does not appear to compile with any version of bouncycastle I can find. WTF? I don't see any way in JCE to use a named curve directly for a key, but it can be used for key generation, and the parameters can then be extracted from that key: // generate bogus keypair(!) with named-curve params

Java/JCE: Decrypting “long” message encrypted with RSA

巧了我就是萌 提交于 2019-11-28 09:33:34
I've got a message contained in an byte[], encrypted with "RSA/ECB/PKCS1Padding". To decrypt it I create a Cipher c and initiate it with c = Cipher.getInstance("RSA/ECB/PKCS1Padding"); Untill now I have only decrypted small messages, using the doFinal() method, returning an byte[] with the decrypted bytes. c.init(Cipher.DECRYPT_MODE, privateKey); byte[] decryptetBytes = c.doFinal(encryptedBytes); But in this case the data is bigger (approx 500 Bytes), and the doFinal() -method throws an exception (javax.crypto.IllegalBlockSizeException: Data must not be longer than 128 bytes). I guess I need

Check for JCE Unlimited Strength Jurisdiction Policy files [duplicate]

强颜欢笑 提交于 2019-11-28 04:52:42
This question already has an answer here: Checking if Unlimited Cryptography is available 9 answers I am usure if the JCE Unlimited Strength Jurisdiction Policy files have been installed correctly in the JVM (because some other part of the system behaves as if they weren't). Can someone supply a code sample that I can use to check if those files are actually being used by the JVM? I found that it can be tested with the following code snippet: int maxKeyLen = Cipher.getMaxAllowedKeyLength("AES"); System.out.println(maxKeyLen); Without the unlimited strength policy files this results in 128,

java.security.NoSuchAlgorithmException:Cannot find any provider supporting AES/ECB/PKCS7PADDING

谁都会走 提交于 2019-11-27 23:30:43
I was trying to encrypt data using AES algorithm. However, with the following exception has occurred. java.security.NoSuchAlgorithmException: Cannot find any provider supporting AES/ECB/PKCS7PADDING Someone know a solution to this issue? My JDK's version is 1.7. You don't want to specify PKCS#7 padding for block cipher use. You want to specify PKCS#5 padding. PKCS#5 is specified for use with block ciphers while PKCS#7 is not (it's use for different places like in S/MIME). I will point out that PKCS#5 and PKCS#7 actually specify exactly the same type of padding (they are the same!), but it's

Default RSA padding in SUN JCE/Oracle JCE

眉间皱痕 提交于 2019-11-27 20:47:38
问题 Could you help me to point out what is the default RSA padding. Precisely, if I create cipher instance as below, sure java is using some sort of padding as encrypted text bytes length always shows 256 bytes for 2048 RSA key irrespective of plain text is one characters or 10 characters. Cipher.getInstance("RSA") I wanted to know what is default padding java use internally if no padding is specified in Cipher.getInstance("RSA"). is that PKCS#1 v 1.5? Thanks, Sam 回答1: It's identical to "RSA/ECB

AES-256 and PKCS7Padding fails in Java

天涯浪子 提交于 2019-11-27 18:34:38
问题 I have a couple of library, C#, PHP and Android where they all encrypt/decrypt a string in the same way so they are all compatible with each other, i.e. C# writes and encrypts data to a database and PHP can successfully decrypt it and return the original string. I now need to do the same thing with a standard Java application, so I've taken the code from my Android library and need libraries but I am getting an exception. As far as I know the code wasn't Android specific so it shouldn't be a

PBKDF2 with bouncycastle in Java

ⅰ亾dé卋堺 提交于 2019-11-27 17:27:14
I'm trying to securely store a password in a database and for that I chose to store its hash generated using the PBKDF2 function. I want to do this using the bouncy castle library but I don't know why I cannot get it to work by using the JCE interface... The problem is that generating the hash in 3 different modes: 1. using the PBKDF2WithHmacSHA1 secret key factory provided by sun 2. using the bouncy castle api directly 3. using the bouncy castle through JCE results in 2 distinct values: one common to the first two and one for the third. Here is my code: //Mode 1 SecretKeyFactory factory =

bouncycastle + JBoss AS7: JCE cannot authenticate the provider BC

杀马特。学长 韩版系。学妹 提交于 2019-11-27 12:06:13
I use BouncyCastle for encryption in my application. When I run it standalone, everything works fine. However, if I put it in the webapp and deploy on JBoss server, I get a following error: javax.servlet.ServletException: error constructing MAC: java.security.NoSuchProviderException: JCE cannot authenticate the provider BC (...) root cause java.lang.Exception: error constructing MAC: java.security.NoSuchProviderException: JCE cannot authenticate the provider BC (...) root cause java.io.IOException: error constructing MAC: java.security.NoSuchProviderException: JCE cannot authenticate the

How to create a secure random AES key in Java?

我只是一个虾纸丫 提交于 2019-11-27 11:32:50
What is the recommended way of generating a secure, random AES key in Java, using the standard JDK? In other posts, I have found this, but using a SecretKeyFactory might be a better idea: KeyGenerator keyGen = KeyGenerator.getInstance("AES"); SecureRandom random = new SecureRandom(); // cryptograph. secure random keyGen.init(random); SecretKey secretKey = keyGen.generateKey(); It would be great if the answer included an explanation of why it is a good way of generating the random key. Thanks! Duncan Jones I would use your suggested code, but with a slight simplification: KeyGenerator keyGen =