| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library dart.crypto; | 5 library dart.crypto; |
| 6 | 6 |
| 7 import 'dart:math'; | 7 import 'dart:math'; |
| 8 | 8 |
| 9 part 'crypto_utils.dart'; | 9 part 'crypto_utils.dart'; |
| 10 part 'hash_utils.dart'; | 10 part 'hash_utils.dart'; |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 abstract class CryptoUtils { | 125 abstract class CryptoUtils { |
| 126 /** | 126 /** |
| 127 * Convert a list of bytes (for example a message digest) into a hex | 127 * Convert a list of bytes (for example a message digest) into a hex |
| 128 * string. | 128 * string. |
| 129 */ | 129 */ |
| 130 static String bytesToHex(List<int> bytes) { | 130 static String bytesToHex(List<int> bytes) { |
| 131 return _CryptoUtils.bytesToHex(bytes); | 131 return _CryptoUtils.bytesToHex(bytes); |
| 132 } | 132 } |
| 133 | 133 |
| 134 /** | 134 /** |
| 135 * Converts a list of bytes (for example a message digest) into a | 135 * Converts a list of bytes into a Base 64 encoded string. |
| 136 * base64 encoded string optionally broken up in to lines of | 136 * |
| 137 * [lineLength] chars separated by '\r\n'. | 137 * The list can be any list of integers in the range 0..255, |
| 138 * for example a message digest. |
| 139 * |
| 140 * If [addLineSeparator] is true, the resulting string will be |
| 141 * broken into lines of 76 characters, separated by "\r\n". |
| 142 * |
| 143 * If [urlSafe] is true, the result is URL and filename safe. |
| 144 * |
| 145 * If [usePadding] is false, No extra padding characters ('=') are |
| 146 * appended to the output. |
| 147 * |
| 148 * Based on [RFC 4648](http://tools.ietf.org/html/rfc4648) |
| 149 * |
| 138 */ | 150 */ |
| 139 static String bytesToBase64(List<int> bytes, [int lineLength]) { | 151 static String bytesToBase64(List<int> bytes, |
| 140 return _CryptoUtils.bytesToBase64(bytes, lineLength); | 152 {bool urlSafe : false, |
| 153 bool addLineSeparator : false}) { |
| 154 return _CryptoUtils.bytesToBase64(bytes, |
| 155 urlSafe, |
| 156 addLineSeparator); |
| 157 } |
| 158 |
| 159 |
| 160 /** |
| 161 * Converts a Base 64 encoded String into list of bytes. |
| 162 * |
| 163 * Decoder ignores "\r\n" sequences from input. By default it also ignores |
| 164 * all illegal characters unless [ignoreInvalidCharacters] is false. |
| 165 * |
| 166 * Accepts both URL safe and unsafe Base 64 encoded strings. |
| 167 * |
| 168 * Based on [RFC 4648](http://tools.ietf.org/html/rfc4648) |
| 169 */ |
| 170 static List<int> base64StringToBytes(String input, |
| 171 {bool ignoreInvalidCharacters : true}) { |
| 172 return _CryptoUtils.base64StringToBytes(input, ignoreInvalidCharacters); |
| 141 } | 173 } |
| 142 } | 174 } |
| 143 | 175 |
| 144 /** | 176 /** |
| 145 * HashExceptions are thrown on invalid use of a Hash | 177 * HashExceptions are thrown on invalid use of a Hash |
| 146 * object. | 178 * object. |
| 147 */ | 179 */ |
| 148 class HashException { | 180 class HashException { |
| 149 HashException(String this.message); | 181 HashException(String this.message); |
| 150 toString() => "HashException: $message"; | 182 toString() => "HashException: $message"; |
| 151 String message; | 183 String message; |
| 152 } | 184 } |
| 153 | 185 |
| OLD | NEW |