Here I read about the basic idea of how to use asymmetric Elliptic Curve encryption to create a product key, here is a quote:
My question is how is it possible to create a product key by a 128-bit Elliptic Curve, since if you encrypt X-length text you get encryption that is much longer than X?
Below is the test code I wrote, an 8-character message encrypted to an array of 28 bytes, what am I wrong with, or is it not at all possible to use the Elliptic Curve to create a 25-character product key?
using Org.BouncyCastle.Crypto.Generators;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Security;
using System.Text;
using System.Linq;
using Org.BouncyCastle.Crypto.Engines;
using System.Diagnostics;
using Org.BouncyCastle.Crypto.Agreement;
using Org.BouncyCastle.Asn1.X9;
using Org.BouncyCastle.Crypto.Digests;
using Org.BouncyCastle.Crypto.Macs;
class Program
{
public static void Main(string[] args)
{
var keyPairGenerator = new ECKeyPairGenerator("ECDH");
var x9 = ECNamedCurveTable.GetByName("secp128r1");
keyPairGenerator.Init(new ECKeyGenerationParameters(new ECDomainParameters(x9), new SecureRandom()));
var keyPair = keyPairGenerator.GenerateKeyPair();
byte[] d = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
byte[] e = new byte[] { 8, 7, 6, 5, 4, 3, 2, 1 };
var p = new IesWithCipherParameters(d, e, 64, 128);
var cipher = new IesEngine(
new ECDHBasicAgreement(),
new Kdf2BytesGenerator(new Sha1Digest()),
new HMac(new Sha1Digest()));
var message = Encoding.UTF8.GetBytes("12345678");
cipher.Init(true, keyPair.Private, keyPair.Public, p);
var encryption = cipher.ProcessBlock(message, 0, message.Length); // encryption length is 28 <==
cipher.Init(false, keyPair.Private, keyPair.Public, p);
var decryption = cipher.ProcessBlock(encryption, 0, encryption.Length);
Debug.Assert(decryption.SequenceEqual(message));
}
}