充气城堡NTRU一代

时间:2014-04-14 21:58:25

标签: java encryption cryptography bouncycastle ntruencrypt

我遇到了下一个问题:我不知道从哪里获取私钥的字节数组来调用正确的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(); 

有没有人遇到同样的问题?

1 个答案:

答案 0 :(得分:0)

您是否已尝试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()));