What keysize can I use to get an Ed25519 KeyPairGenerator instance?

I’m trying to get a KeyPairGenerator instance for Ed25519.

I’d also like to provide an explicit SecureRandom instance. There’s an initialize method that accepts an int, the keysize, and a SecureRandom.

What value can I pass as a keysize argument?

KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("Ed25519");
SecureRandom secureRandom = new SecureRandom();
int keysize = 123; /* what's an appropriate value? */

keyPairGenerator.initialize(keysize, secureRandom);

KeyPair keyPair = keyPairGenerator.generateKeyPair();

The above throws

Exception in thread "main" java.security.InvalidParameterException: Unsupported size: 123
    at jdk.crypto.ec/sun.security.ec.ParametersMap$1.get(ParametersMap.java:78)
    at java.base/java.util.Optional.orElseThrow(Optional.java:403)
    at jdk.crypto.ec/sun.security.ec.ParametersMap.getBySize(ParametersMap.java:102)
    at jdk.crypto.ec/sun.security.ec.ed.EdDSAParameters.getBySize(EdDSAParameters.java:312)
    at jdk.crypto.ec/sun.security.ec.ed.EdDSAKeyPairGenerator.initialize(EdDSAKeyPairGenerator.java:75)
    at java.base/java.security.KeyPairGenerator$Delegate.initialize(KeyPairGenerator.java:671)

So what is an appropriate value?

6

See the Javadoc for KeyPairGeneratorSpi

In case the client does not explicitly initialize the KeyPairGenerator (via a call to an initialize method), each provider must supply (and document) a default initialization. See the Keysize Restriction sections of the JDK Providers document for information on the KeyPairGenerator defaults used by JDK providers. However, note that defaults may vary across different providers. Additionally, the default value for a provider may change in a future version. Therefore, it is recommended to explicitly initialize the KeyPairGenerator instead of relying on provider-specific defaults.

The SunEC Provider described in the linked document supports Ed25519 .

Under Keysize Restrictions for the various supported algorithms, it states that the “Default Keysize” for Ed25519 is 255. It additionally states the following restriction

Keysize must be 255

In other words, the only valid value is 255.

keyPairGenerator.initialize(255, secureRandom);

Alternatively, since this value is fixed, you shouldn’t need to provide it. Instead, use the initialize overload that accepts an AlgorithmParameterSpec and pass the corresponding NamedParameterSpec. For example,

keyPairGenerator.initialize(NamedParameterSpec.ED25519, new SecureRandom());

Solution see code:

KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("Ed25519");
keyPairGenerator.initialize(255,new SecureRandom());
KeyPair keyPair = keyPairGenerator.generateKeyPair();

Solution found using the debugger: keysize=32, bits=255

The answer is 255!

7

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật