Avatar
Please consider registering
guest
sp_LogInOut Log Insp_Registration Register
Register | Lost password?
Advanced Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Feed Topic RSSsp_TopicIcon
org.bouncycastle.util.encoders.DecoderException when trying to create UserIdenty with .der and .pem file
June 22, 2026
12:23, EEST
Avatar
rocket science
Member
Members
Forum Posts: 133
Member Since:
March 16, 2017
sp_UserOfflineSmall Offline

Hi,

basically the creation of a UserIdentity using a .der and .pem file works.

But now I have a specific case, where the .der and .pem file is provided by the EQ vendor to be able to connect to the OpcUA server and it seems that the .pem file can not be loaded correctly.

The code to create the user identy (with SDK version 4.10.2-62) is following:

UserIdentity userIdentity = new UserIdentity(new File(“UserCert.der”), new File(“UserCert.pem”), “pwd”);

The exception is:

org.bouncycastle.util.encoders.DecoderException: unable to decode base64 string: invalid characters encountered in base64 data
at org.bouncycastle.util.encoders.Base64.decode(Unknown Source)
at com.prosysopc.ua.stack.transport.security.BcCryptoProvider.base64Decode(SourceFile:78)
at com.prosysopc.ua.stack.utils.CryptoUtil.base64Decode(SourceFile:122)
at com.prosysopc.ua.stack.transport.security.PrivKey.load(SourceFile:117)
at com.prosysopc.ua.stack.transport.security.PrivKey.load(SourceFile:191)
at com.prosysopc.ua.SecureIdentity.a(SourceFile:473)
at com.prosysopc.ua.SecureIdentity.(SourceFile:235)
at com.prosysopc.ua.UserIdentity.(SourceFile:123)

The .der file looks like this (I’ve removed th middle part for better readability)

UserCert.der

0‚Ê0‚² ®É¢r®Vá,^0å}C¸n:Oê0
*†H†÷
….
5²fØad˾ò»‡º ×–_

The .pem file contains a ‘BEGIN/END CERTIFICATE’ section and a ‘BEGIN/END PRIVATE KEY’ section like shown here:

—–BEGIN CERTIFICATE—–
MIIGyjCCBLKgAwIBAgIUD67JonKuVuEsHV4w5X1DuG46T+owDQYJKoZIhvcNAQEL
….
ZMu+8rsDh7oaANeWAV8=
—–END CERTIFICATE—–
—–BEGIN PRIVATE KEY—–
MIIJQQIBADANBgkqhkiG9w0BAQEFAASCCSswggknAgEAAoICAQCcDX0o7ADB8gJb
….
bstj/beIj9MfXzAsgd84KMZCKK3m
—–END PRIVATE KEY—–

When I remove the ‘BEGIN/END CERTIFICATE’ section, the UserIdenty can be created.

So it seems that the .pem file shall contain only the ‘BEGIN/END PRIVATE KEY’ section, but not the CERTIFICATE, right?

Is there any specification that it should be like this?

Or is there any way to load the UserIdentity with a .der and .pem file which contains CERTIFICATE and PRIVATE KEY’

P.S. The UaExpert can load the UserIdentity using the .der and .pem (including CERTIFICATE and PRIVATE KEY) without problems.

Thank you for you help!

June 23, 2026
12:57, EEST
Avatar
Lusetti
Moderator
Members

Moderators
Forum Posts: 8
Member Since:
May 5, 2020
sp_UserOfflineSmall Offline

Hello,

This constructor expects the certificate and private key as separate files. The .der file is used as the certificate file, and the .pem file should contain only the private key. Therefore, removing the BEGIN CERTIFICATE / END CERTIFICATE block from the PEM file is the correct workaround.

OPC UA itself does not mandate this local PEM file layout. Tools such as UaExpert may accept a PEM file containing both certificate and private key, but this SDK constructor expects the private key file separately.

June 24, 2026
12:52, EEST
Avatar
rocket science
Member
Members
Forum Posts: 133
Member Since:
March 16, 2017
sp_UserOfflineSmall Offline

Thanks for clarification.

Is there any way to accept a .pem file which contains both using the SDK?

June 25, 2026
11:47, EEST
Avatar
Lusetti
Moderator
Members

Moderators
Forum Posts: 8
Member Since:
May 5, 2020
sp_UserOfflineSmall Offline

Unfortunately the SDK doesn’t have helpers to parse private key/cert bundled PEM files. The easiest way would be the workaround provided above.

I’ll make an issue on this as a possible future improvement.

June 29, 2026
13:36, EEST
Avatar
rocket science
Member
Members
Forum Posts: 133
Member Since:
March 16, 2017
sp_UserOfflineSmall Offline

Thanks for taking care of this.

In the meantime I’m using the workaround above.

Forum Timezone: Europe/Helsinki
Most Users Ever Online: 1919
Currently Online:
Guest(s) 35
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Heikki Tahvanainen: 402
hbrackel: 149
rocket science: 128
pramanj: 86
Francesco Zambon: 83
Ibrahim: 78
Sabari: 62
kapsl: 57
gjevremovic: 49
Xavier: 43
Member Stats:
Guest Posters: 0
Members: 912
Moderators: 7
Admins: 1
Forum Stats:
Groups: 3
Forums: 15
Topics: 1599
Posts: 6757
Newest Members:
stefankaleski, TomodachiLifeROM, CarbixTools, DrMatthiasArnold, hbf, AlbertPycle, issacwilloughby, Knut, morrisvqd188879, heathdallachy85
Moderators: Jouni Aro: 1059, Pyry: 1, Petri: 1, Bjarne Boström: 1106, Jimmy Ni: 26, Matti Siponen: 372, Lusetti: 1
Administrators: admin: 1