| 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 crypto.crypto_utils; | 5 library crypto.crypto_utils; |
| 6 | 6 |
| 7 import 'base64.dart'; | 7 import 'base64.dart'; |
| 8 | 8 |
| 9 /// Utility methods for working with message digests. | 9 /// Utility methods for working with message digests. |
| 10 abstract class CryptoUtils { | 10 abstract class CryptoUtils { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 /// | 24 /// |
| 25 /// The list can be any list of integers from 0 to 255 inclusive, for example | 25 /// The list can be any list of integers from 0 to 255 inclusive, for example |
| 26 /// a message digest. | 26 /// a message digest. |
| 27 /// | 27 /// |
| 28 /// If [addLineSeparator] is true, the resulting string will be | 28 /// If [addLineSeparator] is true, the resulting string will be |
| 29 /// broken into lines of 76 characters, separated by "\r\n". | 29 /// broken into lines of 76 characters, separated by "\r\n". |
| 30 /// | 30 /// |
| 31 /// If [urlSafe] is true, the resulting string will be URL- and filename- | 31 /// If [urlSafe] is true, the resulting string will be URL- and filename- |
| 32 /// safe. | 32 /// safe. |
| 33 static String bytesToBase64(List<int> bytes, | 33 static String bytesToBase64(List<int> bytes, |
| 34 {bool urlSafe: false, bool addLineSeparator: false}) { | 34 {bool urlSafe: false, bool addLineSeparator: false}) => |
| 35 return BASE64.encode(bytes, | 35 BASE64.encode(bytes, |
| 36 urlSafe: urlSafe, addLineSeparator: addLineSeparator); | 36 urlSafe: urlSafe, addLineSeparator: addLineSeparator); |
| 37 } | |
| 38 | 37 |
| 39 /// Converts a [Base64-encoded][rfc] String into list of bytes. | 38 /// Converts a [Base64-encoded][rfc] String into list of bytes. |
| 40 /// | 39 /// |
| 41 /// [rfc]: https://tools.ietf.org/html/rfc4648 | 40 /// [rfc]: https://tools.ietf.org/html/rfc4648 |
| 42 /// | 41 /// |
| 43 /// This ignores "\r\n" sequences in [input]. It accepts both URL-safe and | 42 /// This ignores "\r\n" sequences in [input]. It accepts both URL-safe and |
| 44 /// -unsafe Base 64 encoded strings. | 43 /// -unsafe Base 64 encoded strings. |
| 45 /// | 44 /// |
| 46 /// Throws a [FormatException] if [input] contains invalid characters. | 45 /// Throws a [FormatException] if [input] contains invalid characters. |
| 47 static List<int> base64StringToBytes(String input) { | 46 static List<int> base64StringToBytes(String input) => BASE64.decode(input); |
| 48 return BASE64.decode(input); | |
| 49 } | |
| 50 } | 47 } |
| OLD | NEW |