| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chrome.browser; | 5 package org.chromium.chrome.browser; |
| 6 | 6 |
| 7 import android.annotation.SuppressLint; | 7 import android.annotation.SuppressLint; |
| 8 import android.content.Context; | 8 import android.content.Context; |
| 9 import android.os.AsyncTask; | 9 import android.os.AsyncTask; |
| 10 import android.util.Log; | 10 import android.util.Log; |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 122 Log.e(TAG, "Could not close key input stream '" + file + "': " +
e); | 122 Log.e(TAG, "Could not close key input stream '" + file + "': " +
e); |
| 123 } | 123 } |
| 124 } | 124 } |
| 125 } | 125 } |
| 126 | 126 |
| 127 private static boolean writeKeyToFile(Context context, String basename, Secr
etKey key) { | 127 private static boolean writeKeyToFile(Context context, String basename, Secr
etKey key) { |
| 128 File file = context.getFileStreamPath(basename); | 128 File file = context.getFileStreamPath(basename); |
| 129 byte[] keyBytes = key.getEncoded(); | 129 byte[] keyBytes = key.getEncoded(); |
| 130 FileOutputStream output = null; | 130 FileOutputStream output = null; |
| 131 if (MAC_KEY_BYTE_COUNT != keyBytes.length) { | 131 if (MAC_KEY_BYTE_COUNT != keyBytes.length) { |
| 132 Log.e(TAG, "writeKeyToFile got key encoded bytes length " + keyBytes
.length + | 132 Log.e(TAG, "writeKeyToFile got key encoded bytes length " + keyBytes
.length |
| 133 "; expected " + MAC_KEY_BYTE_COUNT); | 133 + "; expected " + MAC_KEY_BYTE_COUNT); |
| 134 return false; | 134 return false; |
| 135 } | 135 } |
| 136 | 136 |
| 137 try { | 137 try { |
| 138 output = new FileOutputStream(file); | 138 output = new FileOutputStream(file); |
| 139 output.write(keyBytes); | 139 output.write(keyBytes); |
| 140 return true; | 140 return true; |
| 141 } catch (Exception e) { | 141 } catch (Exception e) { |
| 142 Log.e(TAG, "Could not write key to '" + file + "': " + e); | 142 Log.e(TAG, "Could not write key to '" + file + "': " + e); |
| 143 return false; | 143 return false; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 } | 220 } |
| 221 Mac mac = Mac.getInstance(MAC_ALGORITHM_NAME); | 221 Mac mac = Mac.getInstance(MAC_ALGORITHM_NAME); |
| 222 mac.init(key); | 222 mac.init(key); |
| 223 return mac; | 223 return mac; |
| 224 } catch (GeneralSecurityException e) { | 224 } catch (GeneralSecurityException e) { |
| 225 Log.w(TAG, "Error in creating MAC instance", e); | 225 Log.w(TAG, "Error in creating MAC instance", e); |
| 226 return null; | 226 return null; |
| 227 } | 227 } |
| 228 } | 228 } |
| 229 } | 229 } |
| OLD | NEW |