[GH-ISSUE #7] Pad Block Corrupted Exception #4

Open
opened 2026-02-26 01:35:45 +03:00 by kerem · 5 comments
Owner

Originally created by @markovejnovic on GitHub (Sep 2, 2019).
Original GitHub issue: https://github.com/junian/Standard.Licensing/issues/7

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'
Originally created by @markovejnovic on GitHub (Sep 2, 2019). Original GitHub issue: https://github.com/junian/Standard.Licensing/issues/7 Hello. After reading a private key created with ```c# 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: ```c# 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' ```
Author
Owner

@markovejnovic commented on GitHub (Sep 2, 2019):

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

<!-- gh-comment-id:527246296 --> @markovejnovic commented on GitHub (Sep 2, 2019): This seems to be an issue with using a `string` in `CreateAndSignPrivateKey`, due to the padding block being truncated as described [here](https://stackoverflow.com/questions/4560461/decryption-error-pad-block-corrupted).
Author
Owner

@markovejnovic commented on GitHub (Sep 2, 2019):

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

<!-- gh-comment-id:527246585 --> @markovejnovic commented on GitHub (Sep 2, 2019): Worth noting that my key generation and license generation code snippets are two different code blocks.
Author
Owner

@brlauuu commented on GitHub (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.

<!-- gh-comment-id:573019031 --> @brlauuu commented on GitHub (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.
Author
Owner

@davidpetric commented on GitHub (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);
        }
    }
}
<!-- gh-comment-id:664167202 --> @davidpetric commented on GitHub (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: ```cs 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); } } } ```
Author
Owner

@mudasar commented on GitHub (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

<!-- gh-comment-id:2251071241 --> @mudasar commented on GitHub (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 in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/Standard.Licensing#4
No description provided.