Search in sources :

Example 66 with KeyData

use of com.google.crypto.tink.proto.KeyData in project tink by google.

the class SignaturePemKeysetReader method readKey.

/**
 * Reads a single PEM key from {@code reader}. Invalid or unparsable PEM would be ignored
 */
private static Keyset.Key readKey(BufferedReader reader, PemKeyType pemKeyType) throws IOException {
    Key key = pemKeyType.readKey(reader);
    if (key == null) {
        return null;
    }
    KeyData keyData;
    if (key instanceof RSAPublicKey) {
        keyData = convertRsaPublicKey(pemKeyType, (RSAPublicKey) key);
    } else if (key instanceof ECPublicKey) {
        keyData = convertEcPublicKey(pemKeyType, (ECPublicKey) key);
    } else {
        // TODO(thaidn): support RSA and EC private keys.
        return null;
    }
    return Keyset.Key.newBuilder().setKeyData(keyData).setStatus(KeyStatusType.ENABLED).setOutputPrefixType(// PEM keys don't add any prefix to signatures
    OutputPrefixType.RAW).setKeyId(Random.randInt()).build();
}
Also used : RSAPublicKey(java.security.interfaces.RSAPublicKey) ECPublicKey(java.security.interfaces.ECPublicKey) RsaSsaPkcs1PublicKey(com.google.crypto.tink.proto.RsaSsaPkcs1PublicKey) EcdsaPublicKey(com.google.crypto.tink.proto.EcdsaPublicKey) RSAPublicKey(java.security.interfaces.RSAPublicKey) Key(java.security.Key) RsaSsaPssPublicKey(com.google.crypto.tink.proto.RsaSsaPssPublicKey) ECPublicKey(java.security.interfaces.ECPublicKey) KeyData(com.google.crypto.tink.proto.KeyData)

Aggregations

KeyData (com.google.crypto.tink.proto.KeyData)66 Test (org.junit.Test)55 Keyset (com.google.crypto.tink.proto.Keyset)17 KeyTemplate (com.google.crypto.tink.KeyTemplate)16 KeyTemplate (com.google.crypto.tink.proto.KeyTemplate)11 GeneralSecurityException (java.security.GeneralSecurityException)10 ByteString (com.google.protobuf.ByteString)9 TreeSet (java.util.TreeSet)9 AesEaxKey (com.google.crypto.tink.proto.AesEaxKey)7 KeysetReader (com.google.crypto.tink.KeysetReader)6 ProtoKey (com.google.crypto.tink.tinkkey.internal.ProtoKey)6 StringReader (java.io.StringReader)6 KeysetHandle (com.google.crypto.tink.KeysetHandle)5 RsaSsaPssPublicKey (com.google.crypto.tink.proto.RsaSsaPssPublicKey)5 BufferedReader (java.io.BufferedReader)5 RSAPublicKey (java.security.interfaces.RSAPublicKey)5 DummyAead (com.google.crypto.tink.TestUtil.DummyAead)4 EcdsaPrivateKey (com.google.crypto.tink.proto.EcdsaPrivateKey)4 Ed25519PrivateKey (com.google.crypto.tink.proto.Ed25519PrivateKey)4 AesEaxKeyFormat (com.google.crypto.tink.proto.AesEaxKeyFormat)3