Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pad Block Corrupted Exception #7

Open
markovejnovic opened this issue Sep 2, 2019 · 5 comments
Open

Pad Block Corrupted Exception #7

markovejnovic opened this issue Sep 2, 2019 · 5 comments

Comments

@markovejnovic
Copy link

Hello. After reading a private key created with

KeyGenerator keyGen = KeyGenerator.Create();
KeyPair keyPair = keyGen.GenerateKeyPair();
string privateKey = keyPair.ToEncryptedPrivateKeyString(args[Array.IndexOf(args, "--private-key") + 1]);
string publicKey = keyPair.ToPublicKeyString();
File.WriteAllText("privKey.txt", privateKey, Encoding.ASCII);
File.WriteAllText("pubKey.txt", publicKey, Encoding.ASCII);

I am unable to create a license by reading the file:

var utilization = Int32.Parse(args[Array.IndexOf(args, "--license-std") + 3]);
var name = args[Array.IndexOf(args, "--license-std") + 1];
var email = args[Array.IndexOf(args, "--license-std") + 2];
var privKeyLocation = args[Array.IndexOf(args, "--license-std") + 4];
var passPhrase = args[Array.IndexOf(args, "--license-std") + 5];
var privKey = File.ReadAllBytes(privKeyLocation);
var privKeyStr = Encoding.ASCII.GetString(privKey);
ILicenseBuilder license = License.New()
	.WithUniqueIdentifier(Guid.NewGuid())
	.As(LicenseType.Standard)
	.WithMaximumUtilization(utilization)
	.LicensedTo(name, email);
License l = license.CreateAndSignWithPrivateKey(privKeyStr, passPhrase);

due to an exception thrown by BouncyCastle:

Org.BouncyCastle.Crypto.InvalidCipherTextException: 'pad block corrupted'
@markovejnovic
Copy link
Author

This seems to be an issue with using a string in CreateAndSignPrivateKey, due to the padding block being truncated as described here.

@markovejnovic
Copy link
Author

Worth noting that my key generation and license generation code snippets are two different code blocks.

@brlauuu
Copy link

brlauuu commented Jan 10, 2020

I am storing the license to a file as well and reading it from it after. However, I'm using File.ReadAllText(path) instead of FIle.ReadAllBytes(path) like you are. Maybe it's worth trying like that.

@davidpetric
Copy link

davidpetric commented Jul 27, 2020

Hello,

For anyone who is trying this NuGet I have downloaded the project source code and run the unit test for generating the license and it worked...then I checked my code and I think that Visual Studio used a wrong namespace for the KeyGenerator class.

Here is my code that generates the private and public keys that works:

namespace StandardLicensingLicenseGenerator
{
    using System;

    public class KeysGenerator
    {
        public Tuple<string, string> Generate(string secretPassPhrase)
        {
            var keyGenerator = Standard.Licensing.Security.Cryptography.KeyGenerator.Create();
            var keyPair = keyGenerator.GenerateKeyPair();

            var privateKey = keyPair.ToEncryptedPrivateKeyString(secretPassPhrase);
            var publicKey = keyPair.ToPublicKeyString();

            return new Tuple<string, string>(privateKey, publicKey);
        }
    }
}

@mudasar
Copy link

mudasar commented Jul 25, 2024

I am facing the same issue every thing was working fine until last year and now i have to generate a new license and all of sudden the keys pad lock broken issue is there. even unable to parse the old licenses (with old keys) base64 error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants