このトピックでは、現在の Java SDK バージョンにおける一般的な問題の解決策を、お客様の参照用に提供します。 エラーコードを使用してエラーを見つけるには、「エラーコードの説明」をご参照ください。
説明
トランザクションを送信するときに SERVICE_TX_WAITING_VERIFY=413 または SERVICE_TX_WAITING_EXECUTE=414 エラーコードが返された場合は、レシートクエリ API を呼び出して問題を見つけてください。
user.key の読み込みエラー。「illegal key size」エラー
ランタイムエラー:
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'}}
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
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
解決策:
特定の JDK のデフォルト構成ではキーの長さが制限されているため、SDK はキーファイルの読み込み時に復号化に失敗します。 その結果、エラーが発生します。
この問題を解決するには、以下に示すように、DemoSample.java の main 関数の先頭にコードセグメントを追加します。
String errorString = "キー長権限の変更に失敗しました";
int newMaxKeyLength;
try {
if ((newMaxKeyLength = Cipher.getMaxAllowedKeyLength("AES")) < 256) {
System.out.println("aes の長さを変更します");
Class c = Class.forName("javax.crypto.CryptoAllPermissionCollection");
Constructor con = c.getDeclaredConstructor();
con.setAccessible(true);
Object allPermissionCollection = con.newInstance();
Field f = c.getDeclaredField("all_allowed");
f.setAccessible(true);
f.setBoolean(allPermissionCollection, true);
c = Class.forName("javax.crypto.CryptoPermissions");
con = c.getDeclaredConstructor();
con.setAccessible(true);
Object allPermissions = con.newInstance();
f = c.getDeclaredField("perms");
f.setAccessible(true);
((Map) f.get(allPermissions)).put("*", allPermissionCollection);
c = Class.forName("javax.crypto.JceSecurityManager");
f = c.getDeclaredField("defaultPolicy");
f.setAccessible(true);
Field mf = Field.class.getDeclaredField("modifiers");
mf.setAccessible(true);
mf.setInt(f, f.getModifiers() & ~Modifier.FINAL);
f.set(null, allPermissions);
newMaxKeyLength = Cipher.getMaxAllowedKeyLength("AES");
}
} catch (Exception e) {
throw new RuntimeException(errorString, e);
}
if (newMaxKeyLength < 256) {
throw new RuntimeException(errorString);
}