public string GenerateRandomPassword() { var passwordBytes = this._platform.GenerateRandomBytes(32); char[] passwordChars = Base64Encoder.EncodeDataToBase64CharArray(passwordBytes); string passwordString = new string(passwordChars).Remove(43).Replace("/", "$"); var sb = new StringBuilder(); for (var i = 0; i != passwordString.Length; ++i) { sb.Append(passwordString[i]); var insertSpace = (i + 1) % 5 == 0; var insertNewLine = (i + 1) % 25 == 0; if (insertNewLine) { sb.Append(Environment.NewLine); } else if (insertSpace) { sb.Append(" "); } } return(sb.ToString()); }
public static XDSSecText CreateXDSSecText(CipherV2 cipherV2) { Guard.NotNull(cipherV2); var xdsSecTextV2Bytes = ByteArrays.Concatenate( // len Sum(len) Start Index new[] { CipherV2.Version }, // 1 1 0 new[] { cipherV2.RoundsExponent.Value }, // 1 2 1 new[] { cipherV2.PlaintextPadding.Value }, // 1 3 2 cipherV2.IV16.GetBytes(), // 16 19 3 cipherV2.MACCipher16.GetBytes(), // 16 35 19 cipherV2.RandomKeyCipher32.GetBytes(), // 32 67 35 cipherV2.MessageCipher.GetBytes() // len 67 + len 67 ); if (xdsSecTextV2Bytes.Length < HeaderLenght) { throw new Exception("Data cannot be shorter than the required header."); } var xdsSecTextV2Base64 = Base64Encoder.EncodeDataToBase64CharArray(xdsSecTextV2Bytes); var sb = new StringBuilder(); const int breakAfter = 74; var charsInLine = 0; foreach (var c in XDSSecSlashText) { sb.Append(c); if (++charsInLine != breakAfter) { continue; } sb.Append(new[] { '\r', '\n' }); charsInLine = 0; } foreach (var c in xdsSecTextV2Base64) { sb.Append(c == '/' ? '$' : c); if (++charsInLine != breakAfter) { continue; } sb.Append(new[] { '\r', '\n' }); charsInLine = 0; } return(new XDSSecText(sb.ToString())); }