내 서버 측에서 RSA 문자열의 암호를 해독하려고합니다. 로컬 서버에서 코드를 실행하는 동안 작동이 잘되는 이지만 GAE에 앱을 배포 할 때 메소드가 빈 문자열 (null이 아님)을 반환합니다.Google App Engine의 RSA
는
(문자열 입력 암호를 해독 할 수있는 바이너리 데이터의 BASE64 표현입니다)이 내 코드입니다 : 원격으로 실행하는 동안
private static String decrypt(String pwd) {
byte[] input = Base64.decode(pwd);
try {
rsaCipher = Cipher.getInstance("RSA/ECB/NoPadding");
} catch (NoSuchAlgorithmException e) {
return null;
} catch (NoSuchPaddingException e) {
return null;
}
KeyFactory keyFactory;
try {
keyFactory = KeyFactory.getInstance("RSA");
} catch (NoSuchAlgorithmException e) {
return null;
}
String modString = "*********";
String privateExponentString = "*********";
RSAPrivateKeySpec prvKeySpec = new RSAPrivateKeySpec(new BigInteger(modString), new BigInteger(privateExponentString));
RSAPrivateKey prvKey;
try {
prvKey = (RSAPrivateKey) keyFactory.generatePrivate(prvKeySpec);
} catch (InvalidKeySpecException e) {
return null;
}
try {
rsaCipher.init(Cipher.DECRYPT_MODE, prvKey);
} catch (InvalidKeyException e) {
return null;
}
byte[] cipherText;
try {
cipherText = rsaCipher.doFinal(input);
} catch (IllegalBlockSizeException e) {
return null;
} catch (BadPaddingException e) {
return null;
}
return new String(cipherText);
}
내가 서버 측에 약간의 디버깅을했다. 모든 항목이 '0'을 포함하면서
rsaCipher.doFinal(input);
돌려 주어 바이트 배열 : 는 그 기능을 알았다.
하십시오 조언,
이 노암 코헨 당신과 안부 감사
우선 (그들을 잡아서 null을 반환). 실제로 발생한 일을 알기 위해서는 오류를 기록해야합니다. –
고맙습니다. 내가 업로드 한 코드 버전에서는 오류 처리 코드를 제거하여 코드를 이해하기 쉬워졌으며 컴파일러가 코드를 받아들이도록 "return null"을 추가했습니다. – thecohenoam