1 // Copyright 2022 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 // 15 /////////////////////////////////////////////////////////////////////////////// 16 17 #include "walkthrough/create_keyset.h" 18 19 // [START tink_walkthrough_create_keyset] 20 #include <memory> 21 22 #include "tink/aead/aead_key_templates.h" 23 #include "tink/keyset_handle.h" 24 #include "tink/util/statusor.h" 25 26 namespace tink_walkthrough { 27 28 using ::crypto::tink::KeysetHandle; 29 using ::crypto::tink::util::StatusOr; 30 using ::google::crypto::tink::KeyTemplate; 31 32 // Creates a keyset with a single AES128-GCM key and return a handle to it. 33 // 34 // Prerequisites for this example: 35 // - Register AEAD implementations of Tink. CreateAead128GcmKeyset()36StatusOr<std::unique_ptr<KeysetHandle>> CreateAead128GcmKeyset() { 37 // Tink provides pre-baked templates. For example, we generate a key template 38 // for AES128-GCM. 39 KeyTemplate key_template = crypto::tink::AeadKeyTemplates::Aes128Gcm(); 40 // This will generate a new keyset with only *one* key and return a keyset 41 // handle to it. 42 return KeysetHandle::GenerateNew(key_template); 43 } 44 45 } // namespace tink_walkthrough 46 // [END tink_walkthrough_create_keyset] 47