@@ -168,28 +168,24 @@ public void ValidateCertificate(string certificate, KalkanValidationType validat
168168 throw new ArgumentNullException ( nameof ( certificate ) ) ;
169169 }
170170
171- int certificateLength = certificate . Length ;
172- int outputInformationLength = 0 ;
173- int ospResponseLength = 0 ;
174-
175- int flag = ( checkCertificateTime ? 0 : KalkanConstants . KC_NOCHECKCERTTIME ) + ( getOscpResponse ? KalkanConstants . KC_GET_OCSP_RESPONSE : 0 ) ;
171+ int certificateLength = Encoding . UTF8 . GetByteCount ( certificate ) ;
172+ int outputInformationLength = 64 * 1024 ;
173+ int ospResponseLength = getOscpResponse ? 128 * 1024 : 0 ;
176174
177- var errorCode = StKCFunctionsType . X509ValidateCertificate ( certificate , certificateLength , ( int ) validationType , validPath , checkTime : 0 , null , ref outputInformationLength , flag , null , ref ospResponseLength ) ;
178- if ( errorCode != KalkanError . BUFFER_TOO_SMALL )
179- {
180- ThrowIfError ( errorCode ) ;
181- }
175+ int flag = ( checkCertificateTime ? 0 : KalkanConstants . KC_NOCHECKCERTTIME ) + ( getOscpResponse ? KalkanConstants . KC_GET_OCSP_RESPONSE : 0 ) ;
182176
183- // Fix: BUFFER_TOO_SMALL
184- ospResponseLength = ospResponseLength + 200 ;
185- outputInformationLength = outputInformationLength + 200 ;
177+ byte [ ] outputInformationBuf = new byte [ outputInformationLength ] ;
178+ byte [ ] ? ospResponseBuf = getOscpResponse ? new byte [ ospResponseLength ] : null ;
186179
187- StringBuilder ospResponseBuilder = new StringBuilder ( ospResponseLength ) ;
188- StringBuilder outputInformationBuilder = new StringBuilder ( outputInformationLength ) ;
189- errorCode = StKCFunctionsType . X509ValidateCertificate ( certificate , certificateLength , ( int ) validationType , validPath , checkTime : 0 , outputInformationBuilder , ref outputInformationLength , flag , ospResponseBuilder , ref ospResponseLength ) ;
180+ var errorCode = StKCFunctionsType . X509ValidateCertificate ( certificate , certificateLength , ( int ) validationType , validPath , checkTime : 0 , outputInformation : outputInformationBuf , ref outputInformationLength , flag , ocsPResponse : ospResponseBuf , ref ospResponseLength ) ;
190181 ThrowIfError ( errorCode ) ;
191- outputInformation = outputInformationBuilder . ToString ( ) ;
192- ospResponse = ospResponseBuilder . ToString ( ) ;
182+
183+ outputInformation = Encoding . UTF8 . GetString ( outputInformationBuf , 0 , outputInformationLength ) ;
184+
185+ if ( getOscpResponse && ospResponseBuf != null && ospResponseLength > 0 )
186+ ospResponse = Convert . ToBase64String ( ospResponseBuf , 0 , ospResponseLength ) ;
187+ else
188+ ospResponse = string . Empty ;
193189 }
194190
195191 public string SignXml ( string content , KalkanSignFlags flags = 0 , string ? certificateAlias = null , string ? signNodeId = null , string ? parentSignNode = null , string parentNameSpace = "" )
@@ -319,7 +315,7 @@ public string SignWsse(string content, string? signNodeId, KalkanSignFlags flags
319315 ThrowIfError ( errorCode ) ;
320316 return Encoding . UTF8 . GetString ( signedPayload , 0 , signedPayloadLength ) . TrimEnd ( '\0 ' ) ;
321317 }
322-
318+
323319 /// <summary>
324320 /// Sing envelope with custom xml attributes
325321 /// </summary>
@@ -530,7 +526,7 @@ private static void ThrowIfError(KalkanError errorCode)
530526
531527 throw new InvalidOperationException ( err . ToString ( ) ) ;
532528 }
533-
529+
534530 private static KalkanSignFlags SignFlags ( KalkanSignType signType , KalkanInputFormat inputFormat ,
535531 KalkanOutputFormat outputFormat )
536532 {
0 commit comments