@@ -679,8 +679,7 @@ private async Task<PayloadData> SwitchAuthenticationAsync(ConnectionSettings cs,
679679 }
680680
681681 // send the password as a NULL-terminated UTF-8 string
682- var passwordBytes = Encoding . UTF8 . GetBytes ( password ) ;
683- Array . Resize ( ref passwordBytes , passwordBytes . Length + 1 ) ;
682+ var passwordBytes = AuthenticationUtility . GetNullTerminatedPasswordBytes ( password ) ;
684683 payload = new ( passwordBytes ) ;
685684 await SendReplyAsync ( payload , ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
686685 return await ReceiveReplyAsync ( ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
@@ -736,8 +735,7 @@ private async Task<PayloadData> SwitchAuthenticationAsync(ConnectionSettings cs,
736735 private async Task < PayloadData > SendClearPasswordAsync ( string password , IOBehavior ioBehavior , CancellationToken cancellationToken )
737736 {
738737 // add NUL terminator to password
739- var passwordBytes = Encoding . UTF8 . GetBytes ( password ) ;
740- Array . Resize ( ref passwordBytes , passwordBytes . Length + 1 ) ;
738+ var passwordBytes = AuthenticationUtility . GetNullTerminatedPasswordBytes ( password ) ;
741739
742740 // send plaintext password
743741 var payload = new PayloadData ( passwordBytes ) ;
@@ -780,8 +778,7 @@ private async Task<PayloadData> SendEncryptedPasswordAsync(
780778#endif
781779
782780 // add NUL terminator to password
783- var passwordBytes = Encoding . UTF8 . GetBytes ( password ) ;
784- Array . Resize ( ref passwordBytes , passwordBytes . Length + 1 ) ;
781+ var passwordBytes = AuthenticationUtility . GetNullTerminatedPasswordBytes ( password ) ;
785782
786783 // XOR the password bytes with the challenge
787784 AuthPluginData = Utility . TrimZeroByte ( switchRequestData ) ;
0 commit comments