2

我需要一个.p12文件才能通过 Apple 的通知服务器进行身份验证,但我发现了一些问题。据我了解,我需要生成 .csr 和我的私钥来识别我的机器。所以我需要在我的本地机器上执行这样的命令:

*$:~/Escritorio/curro/certificados$ openssl req -out CSR.csr -new -newkey rsa:2048 -nodes -keyout privateKey.key
Generating a 2048 bit RSA private key

将新的私钥写入“privateKey.key”

现在,使用我的 CSR.csr 文件,我需要登录到:

https://developer.apple.com/account/ios/certificate/certificateCreate.action?formID=62653259

然后我提供之前生成的 .csr 文件,系统给我一个 .cer 文件 (aps_development.cer) 。现在,有了这个 .cer 文件,我必须生成它 .p12 等效文件。为此,我需要从 Apple 生成的 .cer 文件开始制作一个 .pem 文件。这是命令:

@Ubuntu:~/Escritorio/curro/certificados$ openssl pkcs12 -export -inkey privateKey.key -in developer_identity.pem -out iphone_dev.p12
Enter Export Password:
Verifying
Enter Export Password:

之后我有一个 .p12 文件,我需要初始化一个 ApnsService 实例,

@Component
public class NotificationServer implements Runnable, BeanFactoryAware {

@Autowired
// APNS channel
private ApnsService serviceApns;
private String apns_payload;

@PostConstruct
public void init() {
// build apns service path_to_apns_certificate, absolute path .p12 file 
String path_to_apns_certificate = config.getProperty("a-path");
//pass used to generate the .p12 file       
String password_apns_cert = config.getProperty("a-path");
log.debug("path_to_apns_certificate: " + path_to_apns_certificate);
//keep an eye with this!, this builder is non thread safe!
ApnsServiceBuilder apnsbuilder = new ApnsServiceBuilder();

String sMaxConections = config.getProperty("maxConections");
log.debug("sMaxConections: " + sMaxConections);
int maxConections = Integer.parseInt(sMaxConections);
apnsbuilder.asPool(maxConections );
String connectWithAppleApns = config.getProperty("apns.production");
log.debug("connectWithAppleApns: " + connectWithAppleApns);
apnsbuilder.withAppleDestination(new Boolean(connectWithAppleApns));
//here the exception is launched!       
apnsbuilder.withCert(path_to_apns_certificate, password_apns_cert);
serviceApns =apnsbuilder.build();       
}
}

这是错误消息:

Caused by: com.notnoop.exceptions.InvalidSSLConfig: java.io.IOException: failed to decrypt safe contents entry: javax.crypto.BadPaddingException: Given final block not properly padded
    at com.notnoop.apns.internal.Utilities.newSSLContext(Utilities.java:88)
    at com.notnoop.apns.ApnsServiceBuilder.withCert(ApnsServiceBuilder.java:167)
    at com.notnoop.apns.ApnsServiceBuilder.withCert(ApnsServiceBuilder.java:134)
    at com.*****.agenda.utils.NotificationServer.init(NotificationServer.java:122)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:346)
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:299)
    at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:132)
    ... 164 more
Caused by: java.io.IOException: failed to decrypt safe contents entry: javax.crypto.BadPaddingException: Given final block not properly padded
    at sun.security.pkcs12.PKCS12KeyStore.engineLoad(PKCS12KeyStore.java:1304)
    at java.security.KeyStore.load(KeyStore.java:1214)
    at com.notnoop.apns.internal.Utilities.newSSLContext(Utilities.java:85)
    ... 174 more
Caused by: javax.crypto.BadPaddingException: Given final block not properly padded
    at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:811)
    at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:676)
    at com.sun.crypto.provider.PKCS12PBECipherCore.implDoFinal(PKCS12PBECipherCore.java:355)
    at com.sun.crypto.provider.PKCS12PBECipherCore$PBEWithSHA1AndRC2_40.engineDoFinal(PKCS12PBECipherCore.java:462)
    at javax.crypto.Cipher.doFinal(Cipher.java:2087)
    at sun.security.pkcs12.PKCS12KeyStore.engineLoad(PKCS12KeyStore.java:1295)
    ... 176 more

谁能给我对此的任何看法?

4

1 回答 1

0

我自己回应。该错误涉及通行证或用户错误,在我的情况下,是用引号保存的通行证!几天没有看到那个错误。

于 2015-01-13T10:30:44.030 回答