@@ -332,8 +332,11 @@ protected int engineGenerateSecret(byte[] sharedSecret, int offset)
332332 this .ecPublic = new Ecc ();
333333 this .ecPrivate .releaseNativeStruct ();
334334 this .ecPrivate = new Ecc ();
335- this .ecPrivate .importPrivateOnCurve (priv , null , this .curveName );
336- zeroArray (priv );
335+ try {
336+ this .ecPrivate .importPrivateOnCurve (priv , null , this .curveName );
337+ } finally {
338+ zeroArray (priv );
339+ }
337340
338341 this .state = EngineState .WC_PRIVKEY_DONE ;
339342
@@ -489,8 +492,11 @@ private void wcInitDHParams(Key key, AlgorithmParameterSpec params)
489492 "Unable to get DH private key from Key object" );
490493 }
491494
492- this .dh .setPrivateKey (dhPriv );
493- zeroArray (dhPriv );
495+ try {
496+ this .dh .setPrivateKey (dhPriv );
497+ } finally {
498+ zeroArray (dhPriv );
499+ }
494500
495501 return ;
496502 }
@@ -531,6 +537,7 @@ private void wcInitECDHParams(Key key, AlgorithmParameterSpec params)
531537 BigInteger privateValue = null ;
532538 BigInteger order = null ;
533539 ECParameterSpec ecParams = null ;
540+ byte [] privKeyBytes ;
534541
535542 if (!(key instanceof ECPrivateKey )) {
536543 throw new InvalidKeyException (
@@ -568,8 +575,15 @@ private void wcInitECDHParams(Key key, AlgorithmParameterSpec params)
568575 throw new InvalidAlgorithmParameterException (
569576 "ECC curve is null, please check algorithm parameters" );
570577 }
571- this .ecPrivate .importPrivateOnCurve (ecKey .getS ().toByteArray (),
578+
579+ privKeyBytes = ecKey .getS ().toByteArray ();
580+
581+ try {
582+ this .ecPrivate .importPrivateOnCurve (privKeyBytes ,
572583 null , this .curveName );
584+ } finally {
585+ zeroArray (privKeyBytes );
586+ }
573587 }
574588
575589 /**
0 commit comments