public string GenerateActivationKey() { var engine = new BlowfishEngine(); var cipher = new CbcBlockCipher(engine); var bbc = new BufferedBlockCipher(cipher); bbc.Init(true, new ParametersWithIV(new KeyParameter(Encoding.ASCII.GetBytes(EncKey)), IV)); var n = Prng.Next(0, 999999); var s = String.Format("{0,6};YNAB4;;;;", n); // must be fixed length due to padding issue var sb = Encoding.ASCII.GetBytes(s); sb[sb.Length - 4] = 0x4; // sb[sb.Length - 3] = 0x4; // padding issue??? sb[sb.Length - 2] = 0x4; // PCKS#5 sb[sb.Length - 1] = 0x4; // var cipherText = new byte[bbc.GetOutputSize(sb.Length)]; var outputLen = bbc.ProcessBytes(sb, 0, sb.Length, cipherText, 0); bbc.DoFinal(sb, outputLen); var encryptedLic = Base32.EncodeByteArray(cipherText); return encryptedLic; }