All Products
Search
Document Center

FAQ

Last Updated: May 08, 2020

This topic provides solutions to common problems in the current Java SDK version for your reference. To use error codes to locate faults, see Error code description.

Note: If the SERVICE_TX_WAITING_VERIFY=413 or SERVICE_TX_WAITING_EXECUTE=414 error code is returned when you send a transaction, call the receipt query API to locate the problem.

user.key loading failure with an “illegal key size” error

Runtime error:
  1. 09:49:40.623 [main] ERROR com.github.lyd.msg.provider.DemoSample - unable to read private key,wrong password? errorCode :{MychainSdkErrorCodeEnum{errorCode='30001', errorDesc='sdk invalid private key'}}
  2. 09:49:40.626 [main] ERROR com.github.lyd.msg.provider.DemoSample - unable to read encrypted data: 1.2.840.113549.1.12.1.3 not available: Illegal key size or default parameters
  3. Exception in thread "main" com.alipay.mychain.sdk.exceptions.MychainSdkException: unable to read encrypted data: 1.2.840.113549.1.12.1.3 not available: Illegal key size or default parameters

ERROR

Solution:

The default configuration of a specific JDK limits the key length, so the SDK fails to decrypt the key file when loading it. As a result, the error occurs.

To resolve the problem, add a code segment to the beginning of the main function in DemoSample.java, as shown below.

  1. String errorString = "Failed to modify key-length permissions";
  2. int newMaxKeyLength;
  3. try {
  4. if ((newMaxKeyLength = Cipher.getMaxAllowedKeyLength("AES")) < 256) {
  5. System.out.println("will modify aes length");
  6. Class c = Class.forName("javax.crypto.CryptoAllPermissionCollection");
  7. Constructor con = c.getDeclaredConstructor();
  8. con.setAccessible(true);
  9. Object allPermissionCollection = con.newInstance();
  10. Field f = c.getDeclaredField("all_allowed");
  11. f.setAccessible(true);
  12. f.setBoolean(allPermissionCollection, true);
  13. c = Class.forName("javax.crypto.CryptoPermissions");
  14. con = c.getDeclaredConstructor();
  15. con.setAccessible(true);
  16. Object allPermissions = con.newInstance();
  17. f = c.getDeclaredField("perms");
  18. f.setAccessible(true);
  19. ((Map) f.get(allPermissions)).put("*", allPermissionCollection);
  20. c = Class.forName("javax.crypto.JceSecurityManager");
  21. f = c.getDeclaredField("defaultPolicy");
  22. f.setAccessible(true);
  23. Field mf = Field.class.getDeclaredField("modifiers");
  24. mf.setAccessible(true);
  25. mf.setInt(f, f.getModifiers() & ~Modifier.FINAL);
  26. f.set(null, allPermissions);
  27. newMaxKeyLength = Cipher.getMaxAllowedKeyLength("AES");
  28. }
  29. } catch (Exception e) {
  30. throw new RuntimeException(errorString, e);
  31. }
  32. if (newMaxKeyLength < 256) {
  33. throw new RuntimeException(errorString);
  34. }