I am trying to force a custom string with a length between 0 and 15 to a 128-bit string, so I can use it as a AesCryptoServiceProvider
key.
I have tried fiddling around with multiple strategies, and have ended up with the following:
if (stringToConvert.Length > 16)
{
StringBuilder sB = new StringBuilder();
char[] chA = stringToConvert.ToCharArray();
int chAMaxLength = chA.Length;
for (int i = 0; i < 16; i++)
{
if (i <= chAMaxLength)
{
sB.Append(chA[i]);
}
}
}
I need a string exactly 16 characters long (16*8 = 128).
I am now stuck with it, and just need a helping hand to go through this obsticle.
I apologize in advance if this may seem simple.
Example:
asd
would become
asdasdasdasdasda
Even better (without a
StringBuilder
):