001// SPDX-FileCopyrightText: 2018 Paul Schaub <vanitasvitae@fsfe.org> 002// 003// SPDX-License-Identifier: Apache-2.0 004 005package org.pgpainless.key.generation.type.rsa; 006 007import javax.annotation.Nonnull; 008import java.security.spec.AlgorithmParameterSpec; 009import java.security.spec.RSAKeyGenParameterSpec; 010 011import org.pgpainless.algorithm.PublicKeyAlgorithm; 012import org.pgpainless.key.generation.type.KeyType; 013 014/** 015 * Key type that specifies the RSA_GENERAL algorithm. 016 */ 017public class RSA implements KeyType { 018 019 private final RsaLength length; 020 021 RSA(@Nonnull RsaLength length) { 022 this.length = length; 023 } 024 025 public static RSA withLength(@Nonnull RsaLength length) { 026 return new RSA(length); 027 } 028 029 @Override 030 public String getName() { 031 return "RSA"; 032 } 033 034 @Override 035 public PublicKeyAlgorithm getAlgorithm() { 036 return PublicKeyAlgorithm.RSA_GENERAL; 037 } 038 039 @Override 040 public int getBitStrength() { 041 return length.getLength(); 042 } 043 044 @Override 045 public AlgorithmParameterSpec getAlgorithmSpec() { 046 return new RSAKeyGenParameterSpec(length.getLength(), RSAKeyGenParameterSpec.F4); 047 } 048}