因此,我正在针对Web服务进行身份验证。我得到的代码示例是.NET C#,这是我从未使用过的语言。
我需要一些帮助来理解C#中发生的事情,因此可以在Objective C中复制它。txtUserPwd是一个带有用户密码的文本框。txtRecivedIV是从另一个服务中提取的IV(稍后会进行一些加密)。
// Pad entered password to multiple of 16
int padLen = 16 - (txtUserPwd.TextLength % 16);
int totalWidth = txtUserPwd.TextLength + padLen;
byte[] password = textConverter.GetBytes(txtUserPwd.Text.PadRight(totalWidth, (char) padLen));
// Decode entered IV
byte[] decodedIV = Convert.FromBase64String(txtReceivedIV.Text);
我猜想第一部分用一些空格填充字符串,但是我不确定多少空格或位置。我猜想第二部分将接收到的IV从Base64转换为文本,然后将其转换为字节字符串?
谢谢你的帮助!
int padLen = 16 - (txtUserPwd.TextLength % 16)
设置padLen
为txtUserPwd.TextLength
超出密码长度的差值,最接近16的倍数。如果密码为8个字符,则为。如果密码为12个字符,则为padLen
4。如果密码为20个字符,则为12。
int totalWidth = txtUserPwd.TextLength + padLen;
只是总结一些东西。
byte[] password = textConverter.GetBytes(txtUserPwd.Text.PadRight(totalWidth, (char) padLen));
让我们分解一下。txtUserPwd.Text.PadRight(totalWidth, (char) padLen)
应该将值填充到总长度为totalWidth
。这将使其长度为16个字符的倍数。textConverter.GetBytes
会将填充的字符串转换为字节数组。可能使用默认编码。所有填充都添加到字符串的末尾。
byte[] decodedIV = Convert.FromBase64String(txtReceivedIV.Text);
这只是将base64字符串转换为字节数组。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句