Home | History | Annotate | Download | only in crypto
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef CRYPTO_OPENPGP_SYMMETRIC_ENCRYPTION_H_
      6 #define CRYPTO_OPENPGP_SYMMETRIC_ENCRYPTION_H_
      7 
      8 #include <string>
      9 
     10 #include "base/strings/string_piece.h"
     11 #include "crypto/crypto_export.h"
     12 
     13 namespace crypto {
     14 
     15 // OpenPGPSymmetricEncrytion implements enough of RFC 4880 to read and write
     16 // uncompressed, symmetrically encrypted data. You can create ciphertext
     17 // compatable with this code from the command line with:
     18 //    gpg --compress-algo=NONE --cipher-algo=AES -c
     19 //
     20 // Likewise, the output of this can be decrypted on the command line with:
     21 //    gpg < input
     22 class CRYPTO_EXPORT OpenPGPSymmetricEncrytion {
     23  public:
     24   enum Result {
     25     OK,
     26     UNKNOWN_CIPHER,  // you forgot to pass --cipher-algo=AES to gpg
     27     UNKNOWN_HASH,
     28     NOT_SYMMETRICALLY_ENCRYPTED,  // it's OpenPGP data, but not correct form
     29     COMPRESSED,  // you forgot to pass --compress-algo=NONE
     30     PARSE_ERROR,  // it's not OpenPGP data.
     31     INTERNAL_ERROR,
     32   };
     33 
     34   static Result Decrypt(base::StringPiece encrypted,
     35                         base::StringPiece passphrase,
     36                         std::string *out);
     37 
     38   static std::string Encrypt(base::StringPiece plaintext,
     39                              base::StringPiece passphrase);
     40 };
     41 
     42 }  // namespace crypto
     43 
     44 #endif  // CRYPTO_OPENPGP_SYMMETRIC_ENCRYPTION_H_
     45 
     46