1

我遇到了下一个问题:我不知道在哪里可以获取用于调用正确 NTRUSigningPrivateKeyParameters 的私钥字节数组。

这是我的代码:

    byte [] b = new byte[16];
    Security.addProvider(new BouncyCastleProvider());

    NTRUSigningKeyGenerationParameters ntruSigningKeyGenerationParameters = NTRUSigningKeyGenerationParameters.TEST157;
    NTRUSigningPrivateKeyParameters ntruSigningPrivateKeyParameters = null;
    NTRUSigner ntruSigner = new NTRUSigner(ntruSigningKeyGenerationParameters.getSigningParameters());

    try {
        ntruSigningPrivateKeyParameters = new NTRUSigningPrivateKeyParameters(b, ntruSigningKeyGenerationParameters); // here I need to get byte array from private key
    } catch (IOException e) {
        e.printStackTrace();
    }

    ntruSigner.init(true, ntruSigningPrivateKeyParameters);
    byte [] res = ntruSigner.generateSignature(); 

有没有人有同样的问题?

4

1 回答 1

1

您是否尝试过NTRUSigningKeyPairGenerator并调用getEncoded()检索到的私钥?

NTRUSigningKeyPairGenerator ntruSigningKeyPairGenerator = new NTRUSigningKeyPairGenerator();
NTRUSigningKeyGenerationParameters ntruSigningKeyGenerationParameters = NTRUSigningKeyGenerationParameters.TEST157;
ntruSigningKeyPairGenerator.init(ntruSigningKeyGenerationParameters);
AsymmetricCipherKeyPair asymmetricCipherKeyPair = ntruSigningKeyPairGenerator.generateKeyPair();
NTRUSigningPrivateKeyParameters params = (NTRUSigningPrivateKeyParameters) asymmetricCipherKeyPair.getPrivate();
System.out.println(Hex.encodeHexString(params.getEncoded()));
于 2014-04-14T22:41:35.390 回答