@@ -87,7 +87,7 @@ public static IRubyObject digest(IRubyObject self, IRubyObject digest, IRubyObje
8787 final ByteList bytes = data .asString ().getByteList ();
8888 try {
8989 Mac mac = getMacInstance (algName );
90- mac .init ( new SecretKeySpec ( keyBytes , mac .getAlgorithm ()) );
90+ mac .init ( new SimpleSecretKey ( mac .getAlgorithm (), keyBytes ) );
9191 mac .update (bytes .getUnsafeBytes (), bytes .getBegin (), bytes .getRealSize ());
9292 return runtime .newString ( new ByteList (mac .doFinal (), false ) );
9393 }
@@ -108,7 +108,7 @@ public static IRubyObject hexdigest(IRubyObject self, IRubyObject digest, IRubyO
108108 final ByteList bytes = data .asString ().getByteList ();
109109 try {
110110 final Mac mac = getMacInstance (algName );
111- mac .init ( new SecretKeySpec ( keyBytes , mac .getAlgorithm ()) );
111+ mac .init ( new SimpleSecretKey ( mac .getAlgorithm (), keyBytes ) );
112112 mac .update (bytes .getUnsafeBytes (), bytes .getBegin (), bytes .getRealSize ());
113113 return runtime .newString ( toHEX ( mac .doFinal () ) );
114114 }
@@ -135,7 +135,7 @@ public IRubyObject initialize(IRubyObject key, IRubyObject digest) {
135135 try {
136136 this .mac = getMacInstance (algName );
137137 this .key = key .asString ().getBytes ();
138- mac .init ( new SecretKeySpec ( this . key , mac .getAlgorithm ()) );
138+ mac .init ( SimpleSecretKey . copy ( mac .getAlgorithm (), this . key ) );
139139 }
140140 catch (NoSuchAlgorithmException e ) {
141141 throw getRuntime ().newNotImplementedError ("Unsupported MAC algorithm (HMAC[-]" + algName + ")" );
@@ -159,7 +159,7 @@ public IRubyObject initialize_copy(final IRubyObject obj) {
159159 try {
160160 this .mac = SecurityHelper .getMac (algName );
161161 this .key = that .key ;
162- mac .init ( new SecretKeySpec ( key , algName ) );
162+ mac .init ( SimpleSecretKey . copy ( algName , key ) );
163163 }
164164 catch (NoSuchAlgorithmException e ) {
165165 throw getRuntime ().newNotImplementedError ("Unsupported MAC algorithm (" + algName + ")" );
0 commit comments