mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-12-22 19:08:00 +01:00
Kotlin conversion: RSA
This commit is contained in:
parent
ca3ff6acce
commit
ac245fb56b
3 changed files with 25 additions and 56 deletions
|
@ -1,48 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2018 Paul Schaub <vanitasvitae@fsfe.org>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
package org.pgpainless.key.generation.type.rsa;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.security.spec.AlgorithmParameterSpec;
|
|
||||||
import java.security.spec.RSAKeyGenParameterSpec;
|
|
||||||
|
|
||||||
import org.pgpainless.algorithm.PublicKeyAlgorithm;
|
|
||||||
import org.pgpainless.key.generation.type.KeyType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Key type that specifies the RSA_GENERAL algorithm.
|
|
||||||
*/
|
|
||||||
public class RSA implements KeyType {
|
|
||||||
|
|
||||||
private final RsaLength length;
|
|
||||||
|
|
||||||
RSA(@Nonnull RsaLength length) {
|
|
||||||
this.length = length;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static RSA withLength(@Nonnull RsaLength length) {
|
|
||||||
return new RSA(length);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return "RSA";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PublicKeyAlgorithm getAlgorithm() {
|
|
||||||
return PublicKeyAlgorithm.RSA_GENERAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getBitStrength() {
|
|
||||||
return length.getLength();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public AlgorithmParameterSpec getAlgorithmSpec() {
|
|
||||||
return new RSAKeyGenParameterSpec(length.getLength(), RSAKeyGenParameterSpec.F4);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,8 +0,0 @@
|
||||||
// SPDX-FileCopyrightText: 2020 Paul Schaub <vanitasvitae@fsfe.org>
|
|
||||||
//
|
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Classes related to RSA.
|
|
||||||
*/
|
|
||||||
package org.pgpainless.key.generation.type.rsa;
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
|
package org.pgpainless.key.generation.type.rsa
|
||||||
|
|
||||||
|
import org.pgpainless.algorithm.PublicKeyAlgorithm
|
||||||
|
import org.pgpainless.key.generation.type.KeyType
|
||||||
|
import java.security.spec.RSAKeyGenParameterSpec
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Key type that specifies the RSA_GENERAL algorithm.
|
||||||
|
*/
|
||||||
|
class RSA private constructor(length: RsaLength): KeyType {
|
||||||
|
|
||||||
|
override val name = "RSA"
|
||||||
|
override val algorithm = PublicKeyAlgorithm.RSA_GENERAL
|
||||||
|
override val bitStrength = length.length
|
||||||
|
override val algorithmSpec = RSAKeyGenParameterSpec(length.length, RSAKeyGenParameterSpec.F4)
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
@JvmStatic
|
||||||
|
fun withLength(length: RsaLength) = RSA(length)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue